Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value restriction. The value 'partialTest' has been inferred to have generic type ... #6509

Closed
TIHan opened this issue Apr 12, 2019 · 4 comments
Labels

Comments

@TIHan
Copy link
Member

TIHan commented Apr 12, 2019

Code doesn't compile.

Repro steps

  1. Put this code at a module level:
open System.Collections

let findCustomer (id:int) = ()

let test (f: int -> 'a) (id: int) (principle: IEnumerable)
    = Some (fun () -> f id)

let partialTest = test findCustomer

Expected behavior

It should compile and give a proper signature.

Actual behavior

It does not compile.

Value restriction. The value 'partialTest' has been inferred to have generic type
    val partialTest : (int -> '_a -> (unit -> unit) option) when '_a :> IEnumerable    
Either make the arguments to 'partialTest' explicit or, if you do not intend for it to be generic, add a type annotation. (using built-in F# compiler)

Known workarounds

Make partialTest generic, let partialTest<'a> = ...

Related information

This compiles at the module level:

let findCustomer (id:int) = ()

let test (f: int -> 'a) (id: int) (principle: string)
    = Some (fun () -> f id)

let partialTest = test findCustomer
@TIHan
Copy link
Member Author

TIHan commented Apr 12, 2019

It could be intended design, but I'm sure users would expect this to work since the one using string does. Therefore, I'm deeming this as a bug until said otherwise.

@dsyme
Copy link
Contributor

dsyme commented Apr 12, 2019

Yes this is by design - IEnumerable is not sealed where string is, and this causes the value restriction to trigger

@dsyme dsyme closed this as completed Apr 12, 2019
@NinoFloris
Copy link
Contributor

@dsyme but there's no flexible type being used here? Why is IEnumerable suddenly being inferred as flexible instead of concretely being IEnumerable?

@TIHan
Copy link
Member Author

TIHan commented Apr 12, 2019

I guess my head is exploding, I'm not sure why a sealed type in this case would cause a value restriction. But this would explain when using a record or DU worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants