Module
Dissect.Class
- Package
- purescript-dissect
- Repository
- PureFunctor/purescript-dissect
Provides the Dissect
and Plug
type classes based on "Clowns to
the Left of bme, Jokers to the Right (Pearl): Dissecting Data
Structures" by Conor McBride.
#Dissect Source
class Dissect :: (Type -> Type) -> (Type -> Type -> Type) -> Constraint
class (Functor p, Bifunctor q) <= Dissect p q | p -> q where
The Dissect
class describes a transformation from a Functor
into a Bifunctor
that dissects a data structure into its
components.
Specifically, it takes a fixed-point recursive data type:
data ListF a n = NilF | ConsF a n
And it's equivalent dissection:
data ListF_2 a n m = ConsF_2 a
Producing the following instance:
instance Dissect (T_1 a) (T_2 a) where
right = case _ of
Left NilF → Right NilF
Left (ConsF a n) → Left (Tuple n (ConsF_2 a))
Right (Tuple (ConsF_2 a) c) → Right (ConsF a c)
See also: Data.Functor.Polynomial
implements combinators for
defining data types generically, giving Dissect
instances for
free.
See also: README.md
for a more in-depth explanation and tutorial.