robrix / Madness

Recursive Descent Into Madness
MIT License
291 stars 14 forks source link

[WIP] Parsers & pretty-printers as Prisms #89

Open robrix opened 9 years ago

robrix commented 9 years ago
neilpa commented 9 years ago

Wow, so that's all a prism really is. Why couldn't someone have simply shown me this code when trying to learn about prisms, lenses, etc. Instead I ended up in the weeds of category theory barely understanding anything.

neilpa commented 9 years ago

I think this and some of your other repos are the closest I've found so far for a pragmatic approach to these concepts.

robrix commented 9 years ago

Yup! The Haskellers will tend to use van Laarhoven lenses, which are a function type which sort of subsumes the separate get/set functions (and a lot more besides) and which compose with normal function composition.

Unfortunately you can’t really represent them in Swift without losing composition using the normal function composition operator, or type inference, or both. @cbarrett had some neat ideas involving phantom types, but I was never able to get it working.

Prisms are neat! I’m using them in Tess for de/serializing, which is what gave me the idea of using them for parsing/pretty-printing.

robrix commented 9 years ago

I think this and some of your other repos are the closest I've found so for to a pragmatic approach to these concepts.

@neilpa: Thank you! I do try.

robrix commented 9 years ago

@neilpa: I should also note that Chris Eidhof’s lens post is what kicked off my (implementation) journey, and @robb has a nice Lens library named Monocle which I intend to add Prism to.

neilpa commented 9 years ago

Thanks for the links, enlightening stuff. Helps to solidify some of the ideas I've been experimenting with for end-to-end modeling of collections for UI as "patch sequences".

robrix commented 9 years ago

Nice! I’ve been using diffs in similar circumstances to that, and have been quite pleased with the results.