Module

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 Unit T
iso (SProxy :: SProxy "B") :: Iso String T
iso (SProxy :: SProxy "C") :: Iso (Tuple Int Number) T
iso (SProxy :: SProxy "D") :: Iso (Tuple Boolean (Tuple Int String)) T

Such tupling is necessary for the implementation of both printers and parsers from the same code structure. See Syntax for a more detailed explanation.

The resulting Iso can always convert "forward" (i.e. from tupled arguments to T), but it can only convert "backward" (i.e. from T to the corresponding tuple) when the given T value was constructed with the given constructor, returning Nothing for all other constructors.

Members

Instances

#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

Instances