Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# and generic types

Tags:

.net

f#

Its possible to create this in f#?

public TTarget Map<TTarget>(string SQL) where TTarget : new()
{
}
like image 282
pedrofernandes Avatar asked Feb 20 '26 02:02

pedrofernandes


2 Answers

let map<'T when 'T: (new: unit -> 'T)> (sql: string) =
    new 'T()
like image 164
Lee Avatar answered Feb 22 '26 17:02

Lee


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

let map (sql: string) = new 'T()
like image 23
Daniel Avatar answered Feb 22 '26 16:02

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!