Here is the code that works fine:
let fxyz = x + y + z let gxy = fxy let hxz = z |> fx
Therefore, I can write the expression "h 1", and FSI displays:
val it : (int -> int -> int) = <fun:it@110-3>
If I call "h 1 2 3", the arguments will be applied in the correct order.
But if the last argument is of a different type, everything becomes different:
let ff xy (z : string) = x + y let gg xy = ff xy let hh x (z : string) = z |> ff x
Now the last hh function raises an error message:
Script.fsx (119.10): error FS0001: type mismatch. Expecting a string -> 'a but given int -> string -> int . string type does not match int type
I understand why this happens - "z" is added to "ff x", which makes it the second argument. But then I would expect that in the first example the expression "h 1 2 3" would not work properly (executed as "f 1 3 2"). But it works just fine.
currying f #
Vagif abilov
source share