[Ur] Polymorphic variants and JSON

Edward Z. Yang ezyang at MIT.EDU
Sat Apr 14 21:32:23 EDT 2012


No, I'm silly; we just don't have a typeclass for empty records.

Edward

Excerpts from Edward Z. Yang's message of Sat Apr 14 21:25:01 -0400 2012:
> I think there is an omission in Urweb's typeclass resolution for variants.
> 
> ezyang at javelin:~/Dev/logitext/meta$ urweb tests/testJson -dumpTypes
> [snip]
>  json_phoneType :
>  Json.json
>   (Basis.variant
>     ([#Mobile = Basis.string, #LandLine = {}, #Secret = {}]))
> [snip]
> ezyang at javelin:~/Dev/logitext/meta$ urweb tests/testJson
> /home/ezyang/Dev/logitext/meta/tests/testJson.ur:61:54-61:62: Can't resolve type class instance
> Class constraint: 
> Basis.show
>  (Basis.variant
>    ([#Mobile = Basis.string, #LandLine = {}, #Secret = {}]))
> /home/ezyang/Dev/logitext/meta/tests/testJson.ur:49:38-49:50: Can't resolve type class instance
> Class constraint: 
> {Mobile : Json.json Basis.string, LandLine : Json.json {}, 
>   Secret : Json.json {}}
> /home/ezyang/Dev/logitext/meta/tests/testJson.ur:40:42-40:53: Can't resolve type class instance
> Class constraint: 
> {Type_ :
>   Json.json
>    (Basis.variant
>      ([#Mobile = Basis.string, #LandLine = {}, #Secret = {}])), 
>   Number : Json.json Basis.string}
> 
> Cheers,
> Edward
> 
> Excerpts from Adam Chlipala's message of Sat Apr 14 20:15:10 -0400 2012:
> > Edward Z. Yang wrote:
> > > Excerpts from Edward Z. Yang's message of Sat Apr 14 19:29:32 -0400 2012:
> > >> This particular permutation gives me:
> > >>
> > >>      /home/ezyang/Dev/logitext/meta/json.ur:300:55-300:69: Can't resolve type class instance
> > >>      Class constraint:  Top.folder[[Type]] rest
> > >>
> > >> and I don't know how to spell the implicit arguments correctly or what
> > >> folder I should be giving it (it's /almost/ 'fl' except that the
> > >> entries in front need to be lopped off).  Is there a version of fold which
> > >> also gives me folders?
> > > Here's an idea: fold once to get a record of folders, and fold again
> > > with that. But maybe the unification won't be clever enough.
> > 
> > Oh, yeah; I didn't think of this issue.  It's probably easier to stop 
> > using [Variant.weaken]; instead, you can choose your accumulator type to 
> > be polymorphic in an extra type-level record to concatenate into the 
> > index to [variant].  (This general pattern appears a few times in 
> > variant.ur, including in the first function definition.)



More information about the Ur mailing list