Created
March 29, 2014 12:14
-
-
Save pasberth/9853427 to your computer and use it in GitHub Desktop.
多相バリアントで Show 的な
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 'a show = [`Show of (string * 'a)] | |
type my_int = [`Show of (string * int)] | |
type my_float = [`Show of (string * float)] | |
type my_str = [`Show of (string * string)] | |
let show (`Show (pretty, x) : [< `Show of (string * 'a) ]) = pretty | |
let print x = print_endline (show x) | |
let mk_my_int x = `Show((string_of_int x), x) | |
let mk_my_float x = `Show((string_of_float x), x) | |
let mk_my_str x = `Show(("\""^x^"\""), x) | |
let () = begin | |
let x = mk_my_int 42 in | |
let y = mk_my_float 3.14 in | |
let z = mk_my_str "answer" in | |
print x; | |
print y; | |
print z; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment