1
(*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

1 Answers1

2

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.

John Coleman
  • 51,337
  • 7
  • 54
  • 119
  • John coleman. Thank you. I am learning SML and I am having hard time understand continuation. Can you tell me any tutorial or any other way from where I can learn more about continuation. – user1313623 Mar 19 '16 at 19:45
  • Unlike some functional languages such as Scheme, continuations are not part of SML -- though various implementations of SML such as SML/NJ provide their own implementations (e.g. SMLofNJ.Cont.callcc). I haven't tried any of them. You could perhaps post another question and someone with experience with them could answer. Before you post another question, see this: http://stackoverflow.com/questions/28956717/what-do-continuations-mean-in-functional-programmingspecfically-sml?rq=1 – John Coleman Mar 19 '16 at 20:28