All,
Here is the type expression which I need to convert to a ML expression:
int -> (int*int -> 'a list) -> 'a list
Now I know this is a currying style expression which takes 2 arguments:
1st argument = Type int
and 2nd argument = Function which takes the previous int value twice and return a list of any type
I am having a hard time figuring such a function that would take an int and return 'a list.
I am new to ML and hence this might be trivial to others, but obviously not me.
Any help is greatly appreciated.
You get an
intand a functionint*int -> 'a list. You’re supposed to return an'a list. So all you need to do is call the function you get with (x,x) (where x is the int you get) and return the result of that. SoNote that this is not the only possible function with type
int -> (int*int -> 'a list) -> 'a list. For example the functionsfun foo x f = f (x, 42)andfun foo x f = f (23, x)would also have that type.Edit:
To make the type match exactly add a type annotation to restrict the return type of f:
Note however that there is no real reason to do that. This version behaves exactly as the one before, except that it only accepts functions that return a list.