Last active
August 29, 2015 14:05
-
-
Save ramntry/dfc03e449f7e9ad75643 to your computer and use it in GitHub Desktop.
Explicit polymorphism in OCaml
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
| type 'value expression = | |
| | Const of 'value | |
| | IfThenElse of bool expression * 'value expression * 'value expression | |
| let rec eval : 'value. 'value expression -> 'value = function | |
| | Const value -> value | |
| | IfThenElse (condition, then_expr, else_expr) -> | |
| if eval condition | |
| then eval then_expr | |
| else eval else_expr | |
| let test_expr = | |
| IfThenElse ( | |
| IfThenElse (Const false, Const false, Const true), | |
| Const "ok", | |
| Const "error" | |
| ) | |
| let () = | |
| print_endline (eval test_expr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment