Skip to content

Instantly share code, notes, and snippets.

@phase
Last active July 24, 2016 22:18
Show Gist options
  • Save phase/aeab76602a85f20a19eae1a1f71183cb to your computer and use it in GitHub Desktop.
Save phase/aeab76602a85f20a19eae1a1f71183cb to your computer and use it in GitHub Desktop.
open Printf
let add () =
let a = Stack.pop Objects.stack in
let b = Stack.pop Objects.stack in
(*
if (a is Int and b is Int) {
a + b
}
else if (a is Int and b is String) {
append a b
}
else if (a is String and b is Int) {
append a b
}
String and Int are defined in:
type stack_object =
| Int of int
| Float of float
| String of string
| CodeBlock of string
*)
let sub () =
printf "Sub not implemented yet\n"
let mul () =
printf "Mul not implemented yet\n"
let div () =
printf "Div not implemented yet\n"
let handle s =
match s with
| "+" -> add ()
| "-" -> sub ()
| "*" -> mul ()
| "/" -> div ()
| _ -> printf "Operator not found: %s\n" s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment