OK, so the interpreter tells us that val cond = fn: bool->'a->'a->'a So x and y are of type 'a, and since cond returns one of these, also returns a thing of type 'a. If parentheses are always evaluated first, and I hope they are, then the expression cond c (x z) (y z) means cond acting on two things of course of type 'a. Here type 'a means the return type of x and y, which must be the same. However, type 'a in the expression cond c x y z means a function that acts of z's type and returns something (doesn't matter what as long as it's always the same type). So, the two expressions are definitely different, but I don't see why that matters. If the condition c is the same in both cases, the same function is going to be applied to z both times. How can this generate different results? |
It's order of evaluation, not type by Mike O'Donnell, 2000, Dec 03
to: