(*function f's definition*)
fun f l j y = l j y
val f = fn : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c
What does the below line say about the function f ?
val f = fn : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c
(*function f's definition*)
fun f l j y = l j y
val f = fn : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c
What does the below line say about the function f ?
val f = fn : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c
To answer this question it helps to rename your identifiers:
fun apply g x y = g x y;
val apply = fn : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c
apply
is equivalent to what you are calling f
. What apply does, informally, is take a function, g
, of two variables (in curried form) and two arguments x,y
and actually applies g to those arguments.
As an example g
, define:
fun sum x y = x + y;
val sum = fn : int -> int -> int
Then, for example:
apply sum 5 7;
val it = 12 : int
In the type signature of apply
the part
('a -> 'b -> 'c)
is the type of g
. It is polymorphic. You can apply any function to arguments of an appropriate type. When you actually use apply
(as I did above with sum
) then the SML compiler will have enough information to figure out what concrete types correspond to the type variables 'a, 'b, 'c
. the overall type of apply is
('a -> 'b -> 'c) -> 'a -> 'b -> 'c
which says that apply
is a function which, when fed a function of type ('a -> 'b -> 'c)
and arguments of type 'a
and 'b
, produces a result of type 'c
. I'm not sure of any immediate use of apply
, though it does serve to emphasize the perspective that functional application is itself a higher-order function.