0

Being new to SML, using SML NJ I recognized this behavior of a function:

- fun test g= fn x=>x;
val test : 'a -> 'b -> 'b = _fn
- test 1 2;
val it : int = 2
- test 1;
val it : '1 -> '1 = _fn

Is it so, that the interpreter uses unit as datatype for the input parameter g, if no value is given for it at the call of the function? If so, why is this happening to g and not the input parameter for the anonymous function?

Sebastian Walla
  • 1,104
  • 1
  • 9
  • 23
  • I don't understand what you are asking. "Is it so, that the interpreter uses unit as datatype for the input parameter g." This isn't true, it uses type `'a`. Also, you are violating the [value restriction](http://mlton.org/ValueRestriction) when doing `test 1`. – Matt Oct 18 '15 at 22:27
  • 1
    This question is very unclear. The result of `test 1` is a function. You can apply it: `it 2;` would result in `val it : int = 2`. – molbdnilo Oct 19 '15 at 14:34
  • Oh okay thanks @molbdnilo . As I'm very new to SML I didn't see that. This just explains my question. – Sebastian Walla Oct 20 '15 at 09:48
  • @Matt Oh okay, didn't hear anything of a value restriction before. So I'm violating the value restriction, because test 1 is not a value? – Sebastian Walla Oct 20 '15 at 09:57

1 Answers1

0

According to @molbdnilo test 1; would only bind the value of the function test (fn x=>x) to it. So 1 is assigned to g at the first call. A call of it with some paramter will execute the fn x=>x part.

Sebastian Walla
  • 1,104
  • 1
  • 9
  • 23