4

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?

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
MiloDC
  • 2,373
  • 1
  • 16
  • 25

1 Answers1

4

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

  • 2
    This is the cause, but the relevant difference isn't that seq is an interface, but rather that list is sealed. Use for example `obj ResizeArray` in place of the list, and it will give the value restriction error as well. – Vandroiy Jan 12 '16 at 13:50