Skip to content

Instantly share code, notes, and snippets.

@abcsharp
Created October 7, 2012 06:17
Show Gist options
  • Save abcsharp/3847287 to your computer and use it in GitHub Desktop.
Save abcsharp/3847287 to your computer and use it in GitHub Desktop.
CustomOperationでくだらない事をしてみた
type Calc() =
[<CustomOperation("clear")>]
member it.Clear _ = 0
[<CustomOperation("invert")>]
member it.Invert a = -a
[<CustomOperation("assign")>]
member it.Assign (_, a) = a
[<CustomOperation("add")>]
member it.Add (a, b) = a + b
[<CustomOperation("sub")>]
member it.Sub (a, b) = a - b
[<CustomOperation("mul")>]
member it.Mul (a, b) = a * b
[<CustomOperation("div")>]
member it.Div (a, b) = a / b
[<CustomOperation("mod")>]
member it.Mod (a, b) = a % b
[<CustomOperation("sqrt")>]
member it.Sqrt a = (float >> sqrt >> int) a
[<CustomOperation("print")>]
member it.Print a = printf "%i" a
member it.Yield a = a
let calc = new Calc()
calc{
assign 1
add 1
print
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment