Skip to content

Instantly share code, notes, and snippets.

@jyc
Created March 15, 2017 04:31
Show Gist options
  • Select an option

  • Save jyc/b21bd20af6aac3a9cec59521986d87eb to your computer and use it in GitHub Desktop.

Select an option

Save jyc/b21bd20af6aac3a9cec59521986d87eb to your computer and use it in GitHub Desktop.
type 'a jsont =
| String : string jsont
| List_of : 'a jsont -> 'a list jsont
let rec convert (type el) (t : el jsont) x : el option =
match t with
| String ->
begin match x with
| `String (s : string) -> Some s
| _ -> None
end
| List_of yt ->
begin match x with
| `List ys ->
Some (List.map (convert yt) ys)
| _ -> None
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment