Module

Dissect.Variant

Package
purescript-dissect
Repository
PureFunctor/purescript-dissect

Row-based sum types, VariantF and VariantB, which form a Dissect instance. Useful for defining data types algebraically while also having decent runtime performance and convenient pattern matching syntax.

#Pair Source

data Pair :: (Type -> Type) -> (Type -> Type -> Type) -> Typedata Pair t0 t1

A pair of a Functor and a Bifunctor.

#VariantF Source

data VariantF :: Row Type -> Type -> Typedata VariantF r a

A row-based sum type of functors applied to a.

Unlike VariantF in the variant package, this type is indexed by a row of Pair types, which is also used to index the VariantB type.

Instances

#VariantFRep Source

newtype VariantFRep :: (Type -> Type) -> (Type -> Type -> Type) -> Type -> Typenewtype VariantFRep p q a

The internal representation for VariantF.

Constructors

  • VariantFRep { bimap :: forall w x y z. (w -> x) -> (y -> z) -> q w y -> q x z, init :: forall c j. p j -> Result p q c j, map :: forall x y. (x -> y) -> (p x -> p y), next :: forall c j. q c j -> c -> Result p q c j, tag :: String, value :: p a }

#injF Source

injF :: forall p q r r' t a. IsSymbol t => Dissect p q => Cons t (Pair p q) r' r => Proxy t -> p a -> VariantF r a

Inject into a variant functor given a tag.

#VariantB Source

data VariantB :: Row Type -> Type -> Type -> Typedata VariantB r a b

A row-based sum type of bifunctors applied to a and b.

Instances

#VariantBRep Source

newtype VariantBRep :: (Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Typenewtype VariantBRep p q a b

The internal representation for VariantB.

Constructors

  • VariantBRep { bimap :: forall w x y z. (w -> x) -> (y -> z) -> q w y -> q x z, init :: forall c j. p j -> Result p q c j, map :: forall x y. (x -> y) -> (p x -> p y), next :: forall c j. q c j -> c -> Result p q c j, tag :: String, value :: q a b }

#injB Source

injB :: forall p q r r' t a b. IsSymbol t => Dissect p q => Cons t (Pair p q) r' r => Proxy t -> q a b -> VariantB r a b

Inject into a variant bifunctor given a tag.

#VariantFMatchCases Source

class VariantFMatchCases :: RowList Type -> Row Type -> Type -> Type -> Constraintclass VariantFMatchCases rl vo a b | rl -> vo a b

Instances

#onMatch Source

onMatch :: forall rl r r1 r2 r3 a b. RowToList r rl => VariantFMatchCases rl r1 a b => Union r1 r2 r3 => Record r -> (VariantF r2 a -> b) -> VariantF r3 a -> b

#match Source

match :: forall rl r r1 r2 a b. RowToList r rl => VariantFMatchCases rl r1 a b => Union r1 () r2 => Record r -> VariantF r2 a -> b