1

In designing a typed programming language with subtypes, you need to decide when a function type A->B is a subtype of a function type C->D.

For example, I know that A <= B to indicate that A is a subtype of B

When is it or is it possible A->B <= C->D ?

Any help explaining this would be much appreciated.

Sam Pepper
  • 45
  • 5
  • 1
    It's a very good question. An intuitive answer would be that `A<=C` and `B<=D` conditions are not enough for `A->B <= C->D`, since not all the possible `A->B` types would make sense. – SK-logic Jan 04 '20 at 13:02
  • 4
    This answers your question, but you need to look up "contravariance" and "covariance" to understand it: https://stackoverflow.com/a/10604305/1292784 . Basically, if function `f`'s signature takes a function `C->D` as an input, you can give it any function `g` that accepts the instances of `C` provided by `f`, and that returns values that `f` can treat as instances of `D`. Thus `A->B <= C->D` if `C<=A` and `B<=D`. – Ose Jan 04 '20 at 21:24

0 Answers0