Data.Intertwine.MkIso
- Package
- purescript-intertwine
- Repository
- collegevine/purescript-intertwine
#MkIso Source
class MkIso t ctor tuple | t ctor -> tuple where
This type class provides the function iso
, which operates on a sum type.
It takes the name of a constructor of that type and returns an Iso
instance that converts between the sum type itself and the chosen
constructor's parameters that are all tupled together, starting with the
right ones.
For example:
data T = A | B String | C Int Number | D Boolean Int String
iso (SProxy :: SProxy "A") :: Iso T Unit
iso (SProxy :: SProxy "B") :: Iso T String
iso (SProxy :: SProxy "C") :: Iso T (Tuple Int Number)
iso (SProxy :: SProxy "D") :: Iso T (Tuple Boolean (Tuple Int String))
Such tupling is necessary for the implementation of both printers and parsers from the same code structure. See ../Syntax.purs for a more detailed explanation.
The resulting Iso can convert "forward" (i.e. from T to the corresponding
tuple) only when the given T value was constructed with the given
constructor, returning Nothing
for all other constructors. It can always
convert "backward" (i.e. from tuple to T).
Members
Instances
(ArgsAsTuple args argsAsTuple) => MkIso (Constructor name args) name argsAsTuple
(ArgsAsTuple args argsAsTuple) => MkIso (Sum (Constructor ctor args) rest) ctor argsAsTuple
(MkIso rest ctor tuple) => MkIso (Sum (Constructor anotherName y) rest) ctor tuple
(Generic t rep, MkIso rep ctor tuple) => MkIso t ctor tuple
#ArgsAsTuple Source
class ArgsAsTuple args tuple | args -> tuple where
This type class takes the Generic-rep representation of sum type arguments and converts them into a series of nested tuples.
Members
argsToTuple :: args -> tuple
tupleToArgs :: tuple -> args
Instances
ArgsAsTuple NoArguments Unit
ArgsAsTuple (Argument a) a
(ArgsAsTuple a ax, ArgsAsTuple b bx) => ArgsAsTuple (Product a b) (Tuple ax bx)