I want to write a function that creates an object from a data stream, e.g.
let nxL<'T when 'T : (new : unit -> 'T)> (sr:StreamReader) =
let line = sr.ReadLine()
if line <> null then
Some(new 'T(line))
else
None
However, this doesn't work as it fails with:
Calls to object constructors on typed parameters cannot be given arguments.
Since a constructor is a function and F# is a functional language this makes no sense to me. Does anyone know how to create a function that takes a type as an argument and returns new instances?