Created
March 10, 2019 11:12
-
-
Save SchlenkR/78d3bf0d2f3deaf2a066b43ba90d369e to your computer and use it in GitHub Desktop.
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
// extend a type from another assembly with 'combine' | |
type List<'a> with | |
static member combine (f, x: List<'a>) : List<'a> = x @ [f] | |
// extend another type from another assembly with 'combine' | |
type System.Int32 with | |
static member combine (f, x: System.Int32) = x + f | |
// extend a type from this assembly with 'combine' | |
type GenTest<'a> = { value: 'a } with | |
static member combine (f, x: GenTest<_>) = { value = f } | |
// the generic 'combine' function | |
let inline combine f (x: ^t) = | |
(^t: (static member combine: _ * ^t -> ^t) (f,x)) | |
///// usage: | |
// this is working: | |
List<_>.combine (2, [1;2;3]) | |
System.Int32.combine (5, 10) | |
// not working ("The type '...' does not support the operator 'combine'"): | |
[1;2;3] |> combine 1 | |
5 |> combine 10 | |
// these are of course working: | |
{ value = 10 } |> combine 5 | |
{ value = "yyy" } |> combine "zzz" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment