[Ur] Utility objectifyUr function in JavaScript

Adam Chlipala adamc at csail.mit.edu
Sat Nov 2 13:50:48 EDT 2019


On 10/28/19 3:35 PM, Mark Clements wrote:
> I found that the following function is very useful for converting Ur/Web
> data structures within JavaScript. This may be useful to others --
> although has it been implemented elsewhere?

Thanks for sharing this code.  It's not obvious to me that this code 
belongs in a general library, since it seems to be based on some 
nontrivial assumptions about which Ur/Web types to handle. For instance, 
I think the code mishandles pairs (records with field names 1 and 2), 
incorrectly identifying them as lists.  It also seems to assume that all 
algebraic datatypes are option-style, which isn't true in general.  For 
instance, a term like A (B (C 7))) will apparently be flatted into 7, 
even if the constructors that were peeled away are conveying important 
information.

If one wants to support the full range of types, then I think it becomes 
clear that the original format is actually a pretty good choice!  At 
least, every one of the features that you flatten away was included 
explicitly to avoid ambiguity.  One possible exception is avoiding 
underscores at the beginnings of some record field names, but in that 
case I was motivated by uniformity (simple map to field names in 
JavaScript just by prepending underscores).



More information about the Ur mailing list