Last active
October 10, 2017 12:56
-
-
Save Leonidas-from-XIV/5fc4a34a0edcee615a526e2ed2c4943c to your computer and use it in GitHub Desktop.
Mapping specifications into function signatures
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 _ elem = | |
| Int : int elem | |
| String : string elem | |
type (_, _) spec = | |
| [] : ('a, 'a) spec | |
| (::) : 'a elem * ('b, 'c) spec -> (('a -> 'b), 'c) spec | |
let decode_elem = function | |
| String -> fun x -> x | |
| Int -> int_of_string | |
let rec decode : type b c . (b, c) spec -> b -> 'd list -> c = function | |
| [] -> f () | |
| _ :: rest -> decode rest | |
decode ["foo"; "32"] [String; Int] (fun str int -> Printf.sprintf "%d %s" int str) | |
|> print_endline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment