Reputation: 9335
Suppose all I know about a function is that it is of type:
int list -> int * string -> int
Is there any way of knowing in advance whether this means:
(int list -> int * string) -> int
or int list -> (int * string -> int)
?
Thanks,
bclayman
Upvotes: 0
Views: 196
Reputation: 51998
->
is right associative in SML type annotations, so int list -> (int * string -> int)
is correct.
Consider this simple experiment in the REPL:
- fun add x y = x+y;
val add = fn : int -> int -> int
add
is a function which, when fed an int, returns a function, namely the function which sends y
to x + y
-- hence its type is int -> (int ->int)
. It isn't a function which, when a fed a function from ints to ints outputs an int (which is what (int -> int) -> int
would be). A somewhat artificial example of the later sort of thing is:
- fun apply_to_zero_and_increment f = 1 + f(0);
val apply_to_zero_and_increment = fn : (int -> int) -> int
If I define fun g(x) = x + 5
then apply_to_zero_and_increment g
returns 6.
Upvotes: 3