Last active
July 24, 2016 22:18
-
-
Save phase/aeab76602a85f20a19eae1a1f71183cb to your computer and use it in GitHub Desktop.
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
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