Skip to content

Instantly share code, notes, and snippets.

@Porges
Created February 23, 2015 21:42
Show Gist options
  • Save Porges/ad4c37de80810406d5d1 to your computer and use it in GitHub Desktop.
Save Porges/ad4c37de80810406d5d1 to your computer and use it in GitHub Desktop.
why doesn't this work?
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