Give the following definition
let fn (id: int) (_:string) = id
I can create a partially applied function
let fnPartial = fn 1
However changing the type of _
to a non sealed type like IEnumerable
let fn (id: int) (_:IEnumerable) = id
Causes a compilation error
Value restriction. The value 'fnPartial' has been inferred to have generic type val fnPartial : ('_a -> int) when '_a :> IEnumerable Either make the arguments to 'fnPartial' explicit or, if you do not intend for it to be generic, add a type annotation. (using built-in F# compiler)
A bug was raised but closed with the following response
Yes this is by design - IEnumerable is not sealed where string is, and this causes the value restriction to trigger
The work around is to add a type annotation
let fn (id: int) (_:IEnumerable ) = id
let fnPartial<'a> = fn 1
Can someone explain
- Whats the crux of the issue
- How does adding a type annotation fix the issue