This code doesn't compile:
let f = fun x y -> x <<< y // bit shift
let g = fun x y -> x <<< y
[<EntryPoint>]
let main _ =
printfn "%d" <| f 1 10
printfn "%d" <| f 1L 10 // error
printfn "%d" <| g 1L 10
0
(7,21): error FS0001: This expression was expected to have type
int
but here has type
int64
I guess the unifier fixed the type parameters associated with f
and g
upon seeing their first occurrences. What governs this process? I think this is very similar to "value restriction" but f
and g
are already eta-expanded! This is a hard problem.
I would surely imagine there's some black magic behind typing predefined operators with ad-hoc polymorphism over integral types, but that's just my speculation. Any information appreciated.