Mercurial > meta
comparison json.urs @ 23:9d6b931fbd13
Implement JSON type class for recursive datatypes, using Mu combinator.
author | Edward Z. Yang <ezyang@mit.edu> |
---|---|
date | Wed, 02 May 2012 11:47:37 -0400 |
parents | 8de201d70b91 |
children |
comparison
equal
deleted
inserted
replaced
22:8de201d70b91 | 23:9d6b931fbd13 |
---|---|
2 | 2 |
3 class json | 3 class json |
4 | 4 |
5 val toJson : a ::: Type -> json a -> a -> string | 5 val toJson : a ::: Type -> json a -> a -> string |
6 val fromJson : a ::: Type -> json a -> string -> a | 6 val fromJson : a ::: Type -> json a -> string -> a |
7 val fromJson' : a ::: Type -> json a -> string -> a * string | |
7 | 8 |
8 val mkJson : a ::: Type -> {ToJson : a -> string, | 9 val mkJson : a ::: Type -> {ToJson : a -> string, |
9 FromJson : string -> a * string} -> json a | 10 FromJson : string -> a * string} -> json a |
10 | 11 |
11 val json_string : json string | 12 val json_string : json string |
17 | 18 |
18 val json_record : ts ::: {Type} -> folder ts -> $(map json ts) -> $(map (fn _ => string) ts) -> json $ts | 19 val json_record : ts ::: {Type} -> folder ts -> $(map json ts) -> $(map (fn _ => string) ts) -> json $ts |
19 val json_variant : ts ::: {Type} -> folder ts -> $(map json ts) -> $(map (fn _ => string) ts) -> json (variant ts) | 20 val json_variant : ts ::: {Type} -> folder ts -> $(map json ts) -> $(map (fn _ => string) ts) -> json (variant ts) |
20 | 21 |
21 val json_unit : json unit | 22 val json_unit : json unit |
23 | |
24 functor Recursive (M : sig | |
25 con t :: Type -> Type | |
26 val json_t : a ::: Type -> json a -> json (t a) | |
27 end) : sig | |
28 datatype r = Rec of M.t r | |
29 | |
30 val json_r : json r | |
31 end |