spartanz / schemaz

A purely-functional library for defining type-safe schemas for algebraic data types, providing free generators, SQL queries, JSON codecs, binary codecs, and migration from this schema definition
https://spartanz.github.io/schemaz
Apache License 2.0
164 stars 18 forks source link

Deal with failure scenario caused by choice of sum type encoding #10

Closed jdegoes closed 5 years ago

jdegoes commented 6 years ago

Sums are encoded as lists of prisms, which means it's possible to fail to get any branch in a sum. That is, you can always set a given branch, but you can fail to retrieve any branch at all, if the user didn't specify enough branches to fully represent the sum type.

I think there's a way to fix this using compositional prisms.

LGLO commented 6 years ago

I'll try to work on this one. My main focus in this program is to firstly learn things, if I stall I'll ask for help or notify you that I can't complete this. Thus if there is anyone keen to work on this issue and can complete it - please do.

jdegoes commented 6 years ago

In order to solve this one, it's necessary to use the full power of Prism, which lets you specify a backup. Then by nesting prisms, you should be able to inductively handle all terms in a sum.

Note this would end up generating something like Schema[Either[Either[Either[[...]]], which would then have to be imap'd to the sum type.

vil1 commented 5 years ago

This issue became irrelevant (at least in its current formulation) since we removed optics from the schema GADT.