I have to use new
to create new instances of dynamically created, anonymous object types that are based on existing base types, or interfaces, using object expressions:
let a = { new System.Object() with member x.ToString() = "F#" }
But in other cases, for example computation expressions, I don't have to write new
at all:
type MaybeBuilder() =
member this.Bind(x, f) = match x with
| None -> None
| Some a -> f a
member this.Return(x) = Some x
let maybe = new MaybeBuilder()
ley maybe2 = MaybeBuilder()
I'd like to ask, when is new
not an optional to write?