google-research / dex-lang

Research language for array processing in the Haskell/ML family
BSD 3-Clause "New" or "Revised" License
1.59k stars 108 forks source link

JSON implementation #474

Open srush opened 3 years ago

srush commented 3 years ago

A json implementation (even write-only) would be useful and allow for more shiny demos.

This seems like a good template, but maybe needs associative maps (https://github.com/google-research/dex-lang/pull/343): https://hackage.haskell.org/package/aeson-0.11.3.0/docs/Data-Aeson-Types.html

Some ideas:

These overlap a bit with Dex libs, but there was a lot of thought put into things like Vega, not sure it is necessary to rewrite from scratch.

oxinabox commented 3 years ago

It might need associative maps, but it probably wouldn't need hashmaps. (I should finish #343 at some point though). Since JSON tends to have small number of keys, and technically speaking one is supposed to preserve order. So a list-backed dictionary would be fine.

API-wise: It would be really nice if we had something that was like Show but was parameterized by MIMEtype and value type. (which is what julia's show is). Then we would define a method for the MIMEtype application/json. Which could for simple types fallback to a generic method that is like show, and for dictionaries and other types (this is a not at all subtle request for multiple-dispatch / multi-parameter type classes)

srush commented 3 years ago

That's helpful thanks @oxinabox .

I now realize this probably needs recursive ADTs to do nicely. Although maybe I'll try a JSONShow approach for fun.