I'm working with fsharp type inferencing and I'm trying to understand how they work. Why is it that
List.filter List.head
is type bool list list -> bool list list
?
List.filter
has the type (just enter List.filter;;
in FSI):
> List.filter;;
val it : (('a -> bool) -> 'a list -> 'a list)
so it takes a 'a -> bool
and results in a 'a list -> 'a list
Now you feed it with
> List.head;;
val it : ('b list -> 'b)
(it's another 'a
really so I renamed it) and now you have:
'a -> bool ~ 'b list -> 'b
you can unify this and see:
'b ~ bool
(from the right-hand-sides of ->
)'a ~ 'b list ~ bool list
(from the left-hand-side)but this all together and you get the answer F#`s type-inference gives you:
'a list -> 'a list
~ ('b list) list -> ('b list) list
~ (bool list) list -> (bool list) list
~ bool list list -> bool list list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With