book-of-examples icon indicating copy to clipboard operation
book-of-examples copied to clipboard

topic: JSON ADT and codecs

Open monmcguigan opened this issue 1 year ago • 5 comments

I'm imagining writing an ADT for JSON structure and then showing how you can write encoders/decoders for this representation.

It would cover modelling data with algebraic data types, pattern matching, encoding/decoding etc.

I like this topic because I feel like there's lots of different details and levels you can dive into.

monmcguigan avatar Mar 24 '24 16:03 monmcguigan

Cool - there was some discussion of this in #14 as well. I think there may be a JSON encoding/decoding package for Roc, but building a scale model from the ground up to show people how it works (in the way that chapters in the JavaScript and Python books built simplified versions of regular expression matchers to show how they work) would be awesome. Cc @FabHof (who's doing a binary encoder/decoder) for thoughts and to synchronize.

gvwilson avatar Mar 25 '24 11:03 gvwilson

Ah I wasn't aware there already was a JSON codec lib in Roc, I will sync with @FabHof on this.

monmcguigan avatar Mar 26 '24 12:03 monmcguigan

For reference: https://github.com/lukewilliamboswell/roc-json

To be honest, I'm not sure about the scope of my part. If you want to talk about Encoding/Decoding I can focus more on the binary representation and bit shifting stuff.

Also this discussion on zulip might be relevant: https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/Encoding.20that.20can.20fail

FabHof avatar Mar 26 '24 14:03 FabHof

Hi again @monmcguigan - just to be clear, the fact that there's a JSON codec in Roc is an argument for including your chapter, not against it: building a scale model that includes the core features of the full module will help people understand how and why it does what it does, and they're more likely to believe this is a "real" problem if there's something for it in the standard library. I'm going to assign this one to you - if you and @FabHof can chat here, on Zulip, or by email about where yours will stop and theirs will start, that would be awesome.

gvwilson avatar Mar 26 '24 14:03 gvwilson

@monmcguigan A thought on this: there are also different approaches to decoding JSON, which beginners might benefit from. This article talks about starting from a simple JsonValue type and then shows where that runs into limitations which motivates building out a decoder system.

So the "scale model" approach Greg mentioned could work, and another way would be to show an alternative (simpler) design to the one found in the roc-json package, and then talk about the tradeoffs of that simpler design which motivate the decoding library.

rtfeldman avatar Apr 06 '24 12:04 rtfeldman