3 ms·
To reply to both my respondents, the link goes exactly to the source for Opaleye's version of the Maybe data type definition. Neatened up, it is data Mayb
by tome 5y ago
To reply to both my respondents, the link goes exactly to the source for Opaleye's version of the Maybe data type definition. Neatened up, it is
data MaybeFields fields =
MaybeFields {
mfPresent :: Field SqlBool
, mfFields :: fields
}
That is, an Opaleye Maybe (MaybeFields) is a pair. The first component is an SQL bool indicating whether it's a Just or a Nothing. The second component is the payload of the Just. If it's a Nothing the fields of the payload will be set to NULL.
- mamcx 5y agoOk, this is for a Maybe/Option, but can't see how can work for any algebraic type. I have this for mine: struct Ag { tag :String, //like "Option.None" data:Vec<Value> //The data inside, if any }
- tome 5y agoArbitrary sum types are just a generalisation of what I wrote. Opaleye doesn't have them (yet?) but rel8 does: https://hackage.haskell.org/package/rel8-1.1.0.0/docs/src/Rel8.Table.Either.html#EitherTable https://hackage.haskell.org/package/rel8-1.1.0.0/docs/src/Re... You have a bool which specifies whether it's left or right, and then two payloads, one for left and one for right.