Created
February 23, 2015 21:42
-
-
Save Porges/ad4c37de80810406d5d1 to your computer and use it in GitHub Desktop.
why doesn't this work?
This file contains hidden or 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 Num<'a> = { | |
add : 'a -> 'a -> 'a; | |
subtract : 'a -> 'a -> 'a; | |
multiply : 'a -> 'a -> 'a; | |
divide : 'a -> 'a -> 'a; | |
} | |
type System.Int32 with | |
static member NumInstance () = | |
{ | |
add = fun x y -> x + y; | |
subtract = fun x y -> x - y; | |
multiply = fun x y -> x * y; | |
divide = fun x y -> x / y; | |
} | |
let inline getNum () : Num<'a> = (^a : (static member NumInstance : unit -> Num<'a>) ()) | |
let inline func x y = | |
let num = getNum() | |
num.divide (num.add x y) x | |
[<EntryPoint>] | |
let main argv = | |
printfn "%A" (func 3 2) // the type 'int' does not support the operator 'NumInstance' | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://github.com/gmpl/FSharpPlus/blob/master/FSharpPlus/Operators.fs#L184-L267 and https://github.com/gmpl/FsControl/blob/master/FsControl.Core/Numeric.fs