Small difference in types

前端 未结 1 393
迷失自我
迷失自我 2021-01-04 13:03

I have three functions that ought to be equal:

let add1 x = x + 1
let add2 = (+) 1
let add3 = (fun x -> x + 1) 

Why do the types of thes

相关标签:
1条回答
  • 2021-01-04 13:18

    This is typically an unimportant distinction, but if you're really curious, see the Arity Conformance for Values section of the F# spec.

    My quick summary would be that (int -> int) is a superset of int -> int. Since add1 and add3 are syntactic functions, they are inferred to have the more specific type int -> int, while add2 is a function value and is therefore inferred to have the type (int -> int) (and cannot be treated as an int -> int).

    0 讨论(0)
提交回复
热议问题