Mercurial > meta
diff 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 |
line wrap: on
line diff
--- a/json.urs Wed May 02 11:47:37 2012 -0400 +++ b/json.urs Wed May 02 11:47:37 2012 -0400 @@ -4,6 +4,7 @@ val toJson : a ::: Type -> json a -> a -> string val fromJson : a ::: Type -> json a -> string -> a +val fromJson' : a ::: Type -> json a -> string -> a * string val mkJson : a ::: Type -> {ToJson : a -> string, FromJson : string -> a * string} -> json a @@ -19,3 +20,12 @@ val json_variant : ts ::: {Type} -> folder ts -> $(map json ts) -> $(map (fn _ => string) ts) -> json (variant ts) val json_unit : json unit + +functor Recursive (M : sig + con t :: Type -> Type + val json_t : a ::: Type -> json a -> json (t a) + end) : sig + datatype r = Rec of M.t r + + val json_r : json r +end