Remove spurious "function that takes"

Fix the section on Fruit function vs apple function.
This commit is contained in:
Florian Loitsch 2017-09-02 20:58:08 +02:00 committed by GitHub
parent 7733322d79
commit b74f7cdd86

View file

@ -185,7 +185,7 @@ The type system has to decide if an instance of type `C` (here `c`) is assignabl
In our example, the type system thus wants to answer: `C <: void Function(C)`? Since `C` is compared to a function type, we have to look at `C`'s `call` method and use that type instead: `void Function(void Function(C))`. The type system can now compare these types structurally: `void Function(void Function(C)) <: void Function(C)`?
It starts by looking at the return types. In our case these are trivially assignable: both are `void`. Next up are the parameter types: `void Function(C)` on the left, and `C` on the right. Since these types are in parameter position, we have to invert the operands. Formally, this inversion is due to the fact that argument types are in contravariant position. Intuitively, it's easy to see that a function that takes a *fruit function* (`Function(Fruit)`) can always be used in places where an *apple function* (`Function(Apple)`) is required: `Function(Fruit) <: Function(Apple)` because `Apple <: Fruit`.
It starts by looking at the return types. In our case these are trivially assignable: both are `void`. Next up are the parameter types: `void Function(C)` on the left, and `C` on the right. Since these types are in parameter position, we have to invert the operands. Formally, this inversion is due to the fact that argument types are in contravariant position. Intuitively, it's easy to see that a *fruit function* (`Function(Fruit)`) can always be used in places where an *apple function* (`Function(Apple)`) is required: `Function(Fruit) <: Function(Apple)` because `Apple <: Fruit`.
Getting back to our example, we had just concluded that the return types of `void Function(void Function(C)) <: void Function(C)` matched and were looking at the parameter types. After switching sides we have to check whether `C <: void Function(C)`.