Created
August 19, 2015 13:50
-
-
Save gsg/ba070114d4d0b605f14e 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
type _ expr = Int : int -> int expr | Float : float -> float expr | |
type any_expr = Any : 'a expr -> any_expr | |
type _ ty = TyInt : int ty | TyFloat : float ty | |
let rec eval : type a . a expr -> a = function | |
| Int i -> i | |
| Float f -> f | |
let rec typeof : type a . a expr -> a ty = function | |
| Int i -> TyInt | |
| Float f -> TyFloat | |
let rec print : type a . a -> a ty -> unit = | |
fun value ty -> | |
match ty with | |
| TyInt -> print_int value | |
| TyFloat -> print_float value | |
let eval_and_print (Any e) = | |
print (eval e) (typeof e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment