Created
August 30, 2012 08:02
-
-
Save metametaclass/3523947 to your computer and use it in GitHub Desktop.
f#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let inline getName arg = | |
( ^a : (member Name : string) arg ) | |
//function type: | |
//val inline getName : | |
// ^a -> string when ^a : (member get_Name : ^a -> string) | |
let inline dumpNamed<'T when 'T : (member Name : string)> (arg:seq<'T>) = | |
arg |> Seq.iter (getName >> printfn "%s") | |
//val inline dumpNamed : | |
// seq< ^T> -> unit when ^T : (member get_Name : ^T -> string) | |
//record with get_Name member | |
type Test = { | |
_Name :string | |
} | |
with | |
member this.Name = this._Name | |
//record with get_Name member (generated by compiler!) | |
type Test1 = { | |
Name :string | |
} | |
let ts = [{_Name="n1"};{_Name="n2"};{_Name="n3"}] | |
let ts1 = [{Name="n11"};{Name="n12"};{Name="n13"}] | |
//type-check pass | |
dumpNamed ts | |
//type-check fails | |
//dumpNamed ts1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment