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) -> Constraintclass (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.

Members

#Plug Source

class Plug :: (Type -> Type) -> (Type -> Type -> Type) -> Constraintclass (Dissect p q) <= Plug p q | p -> q where

The Plug class describes how to take a Bifunctor dissection and turn it back into the undissected Functor.

Members

  • plug :: forall x. x -> q x x -> p x

#plant Source

plant :: forall p q c j. Dissect p q => (q c j) -> c -> Either (Tuple j (q c j)) (p c)

#pluck Source

pluck :: forall p q c j. Dissect p q => p j -> Either (Tuple j (q c j)) (p c)

#tmap Source

tmap :: forall p q a b. Dissect p q => (a -> b) -> p a -> p b

Types that can be dissected are Functors.

#tsequence Source

tsequence :: forall m p q a. Dissect p q => MonadRec m => p (m a) -> m (p a)

Types that can be dissected are Traversable, provided that the Monad has a MonadRec instance.

#ttraverse Source

ttraverse :: forall m p q a b. Dissect p q => MonadRec m => (a -> m b) -> p a -> m (p b)

Types that can be dissected are Traversable, provided that the Monad has a MonadRec instance.