Created
June 12, 2014 16:48
-
-
Save smondet/a73d5cc00e9678fd26b2 to your computer and use it in GitHub Desktop.
This file contains 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 (_,_) safety = Safe : ('a,'a option) safety | Unsafe : ('a,'a) safety | |
let ios: type a. (int, a) safety -> string -> a = fun safety s -> | |
match safety with | |
| Safe -> (try Some (int_of_string s) with _ -> None) | |
| Unsafe -> int_of_string s | |
let () = | |
assert (ios Safe "dskljf" = None); | |
(try | |
ignore (ios Unsafe "dskljf"); assert false | |
with _ -> ()); | |
assert (ios Safe "42" = Some 42); | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment