简体   繁体   中英

F# and generic types

Its possible to create this in f#?

public TTarget Map<TTarget>(string SQL) where TTarget : new()
{
}
let map<'T when 'T: (new: unit -> 'T)> (sql: string) =
    new 'T()

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM