pedrofernandes
pedrofernandes

Reputation: 16854

F# and generic types

Its possible to create this in f#?

public TTarget Map<TTarget>(string SQL) where TTarget : new()
{
}

Upvotes: 2

Views: 205

Answers (2)

Daniel
Daniel

Reputation: 47904

Actually, the constraint is unnecessary. This works just as well.

let map (sql: string) = new 'T()

Upvotes: 5

Lee
Lee

Reputation: 144126

let map<'T when 'T: (new: unit -> 'T)> (sql: string) =
    new 'T()

Upvotes: 5

Related Questions