F# value restriction for seq<obj> but not list<obj>?

79 Views Asked by At

Value restriction error:

let myFn (s : string) (args : obj seq) = ()
let myOtherFn = myFn ""

No value restriction error:

let myFn (s : string) (args : obj list) = ()
let myOtherFn = myFn ""

Why?

1

There are 1 best solutions below

1
Ludwig Valda Vasquez On

All bindings are a subject for automatic generalization.

Since seq<'T> is an interface (an alias for IEnumrable) , the inferred type for myOtherFn would be
val myOtherFn : ('_a -> unit) when '_a :> seq<obj>
which is generic, yet, myOtherFn is not a function declaration (read Value Restriction part in the link above), so automatic generalization cannot deduce that this is the same as val myOtherFn : seq<obj> -> unit.

To force automatic generalization you can add explicit parameter to myOtherFn
let myOtherFn args = myFn "" args

Related Questions in F#