Created
March 17, 2014 14:58
-
-
Save mausch/9600851 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
// https://twitter.com/__josejuan__/status/445564129521434624 | |
// dummy definitions: | |
type Variable() = class end | |
type Expression() = class end | |
type Term() = class end | |
// overloads: | |
type E = | |
static member Sum(x: Variable list) = 0 | |
static member Sum(x: Expression list) = 1 | |
static member Sum(x: Term list) = 2 | |
// example: | |
let _ = | |
let v = E.Sum [Variable()] | |
let e = E.Sum [Expression()] | |
let t = E.Sum [Term()] | |
() | |
// alternatively, using inline overloads: | |
type SumClass = SumClass with | |
static member Sum(x: Variable list) = 0 | |
static member Sum(x: Expression list) = 1 | |
static member Sum(x: Term list) = 2 | |
let inline sum x = | |
let inline isum (a: ^a, b: ^b) = ((^a or ^b) : (static member Sum: ^b -> int) b) | |
isum (SumClass, x) | |
// example: | |
let _ = | |
let v = sum [Variable()] | |
let e = sum [Expression()] | |
let t = sum [Term()] | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment