4
votes

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

1 Answers

4
votes

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