Type F # inference

I work with pins like fsharp and I'm trying to figure out how they work. Why is this

List.filter List.head 

is the type bool list list -> bool list list ?

+7
type-inference f #
source share
1 answer

List.filter is of type (just type List.filter;; in FSI):

 > List.filter;; val it : (('a -> bool) -> 'a list -> 'a list) 

therefore, it takes the value 'a -> bool and leads to 'a list -> 'a list

Now you feed him

 > List.head;; val it : ('b list -> 'b) 

(this is another 'a , so I renamed it), and now you have:

 'a -> bool ~ 'b list -> 'b 

you can combine this and see:

  • 'b ~ bool (from the right side -> )
  • 'a ~ 'b list ~ bool list (left side)

but all this together, and you will get an answer. An output like F # gives you:

 'a list -> 'a list ~ ('b list) list -> ('b list) list ~ (bool list) list -> (bool list) list ~ bool list list -> bool list list 
+10
source share

All Articles