Reputation: 517
I've searched on Google but I didn't find anything about type profiles for ML.
For example for: fun bar(a, b, c) = [a, b + hd(c)];
the type profile is: int * int * int list -> int list and for
fun weird x z = [x, tl(z)]
the type profile is 'a list -> 'a list -> 'a list list
but I don't understand the logic behind it.
Upvotes: 1
Views: 78
Reputation: 36088
"Type profile" isn't a thing. You probably mean type inference. It is easy in this case. First, note that a curried function definition like yours is equivalent to writing
val weird = fn x => fn z => [x, tl z]
Now:
weird : A -> B -> C
for some types A, B, C.C
must be D list
for some type D.tl
on z
, so B
must be E list
for some type E.E list
, so D
must be the same as E list
.x
is used as an element of the same list, so A
must be E list
as well.'a
for E
.Putting all this together, you get
weird : 'a list -> 'a list -> 'a list list
Upvotes: 4