There are no problems here:
module Seq =
let private rnd = Random Environment.TickCount
let random =
fun (items : 'T seq) ->
let count = Seq.length items
items |> Seq.nth (rnd.Next count)
The signature Seq.randomis equal items:seq<'T> -> 'T. Things are good.
Yes, I know that I could just let random items = [...], this is not a question.
The thing is, it is itemssuddenly limited to the type seq<obj>when I do this:
module Seq =
let random =
let rnd = Random Environment.TickCount
fun (items : 'T seq) ->
let count = Seq.length items
items |> Seq.nth (rnd.Next count)
... i.e. I am adding an object Randomas a closure. If I'm over Random, Intellisense shows me what the signature has become items:seq<obj> -> obj.
Interestingly, if I select the code and delete [Alt]+[Enter]to execute it in F # Interactive, the signature is displayed as seq<'a> -> 'a. Wth ??
So what's going on here? Why confusion and inconsistency in type inference?
source
share