Created
April 9, 2015 09:05
-
-
Save pirrmann/757b1ff276244d4e7f5b to your computer and use it in GitHub Desktop.
Statically resolved member constraints
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
type SyntaxToken = string | |
type X = | |
{ | |
SomeProperty: string | |
} with | |
member this.AddModifiers(tokens:SyntaxToken array) = | |
{ this with | |
SomeProperty = sprintf "%s + %s" (this.SomeProperty) (System.String.Join(",", tokens)) } | |
type Y = | |
| SomeDUType of int | |
| SomeOtherDUType of int with | |
member this.AddModifiers(tokens:SyntaxToken array) = | |
match this with | |
| SomeDUType i -> SomeOtherDUType (i+1) | |
| SomeOtherDUType i -> SomeDUType (i+1) | |
let inline addModifiers< ^T when ^T : (member AddModifiers : SyntaxToken array -> ^T)> tokens (input:^T) = | |
(^T : (member AddModifiers : SyntaxToken array -> ^T) (input, tokens)) | |
// tests | |
let x = { SomeProperty = "Test" } |> addModifiers [|"a";"b"|] | |
let y = SomeDUType 1 |> addModifiers [|"a";"b"|] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍