I have defined a function like the following:
let ff (f1: a_function) (f2: a_function) (v0: type1) (v1: type2): type3 = ...
And another function like the following works:
let f: type1 -> type2 -> type3 = ff f1 f2
But another declaration like the following does not work:
let f (v0: type1) (v1: type2): type3 = ff f1 f2
The error message is:
Error: This expression has type
type1 -> type2 -> type3
but an expression was expected of type type3
I have always thought that let f: type1 -> type2 -> type3 is same as let f (v0: type1) (v1: type2): type3. Could anyone tell me why the first declaration works but not the second?
Thank you very much
PS1: My key question is, given let f (v0: type1) (v1: type2): type3 = ff f1 f2, isn’t the type of f type1 -> type2 -> type3?
If let f (v0: type1) (v1: type2): type3 = ff f1 f2 and let f (v0: type1) (v1: type2): type3 = ff f1 f2 returns same type of f, what is the difference between these 2 signatures?
Arguments
v0,v1of your second definition are dangling. This declaration works, on the other hand:The last line answers your PS (notice I haven’t specified the return type of
g, to let the compiler infer what it should be): since its definition ignores argumentsv0andv1, the curried meaning ofg (v0:type1) (v1:type2) = ff f1 f2gives it the typetype1 -> type2 -> type1 -> type2 -> type3. Basically, you require two additional arguments whose value you’re going to throw away (not passing them toff f1 f2, which is going to require two of its own).And indeed, when declaring the above module, part of the response of the compiler is: