Module

Dissect.Class

Package
purescript-dissect
Repository
PureFunctor/purescript-dissect

Provides the Dissect type class based on the "Clowns to the Left of me, Jokers to the Right (Pearl): Dissecting Data Structures" paper by Conor McBride.

#Result Source

newtype Result :: (Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Typenewtype Result p q c j

The result of a dissection step over some data structure p, which can either be a yield, indicating that additional steps would have to be performed; or a return, indicating that the dissection has finished.

Constructors

  • Result (Variant (return :: p c, yield :: { j :: j, qcj :: q c j }))

Instances

#yield Source

yield :: forall p q c j. j -> (q c j) -> Result p q c j

#return Source

return :: forall p q c j. p c -> Result p q c j

#Dissect Source

class Dissect :: (Type -> Type) -> (Type -> Type -> Type) -> Constraintclass (Functor p, Bifunctor q) <= Dissect p q | p -> q where

The type class for dissectible data structures, which generalizes the traversal of some Functor p given an intermediary Bifunctor q.

Members

  • init :: forall c j. p j -> Result p q c j

    Initializes a dissection given the base structure p j.

  • next :: forall c j. q c j -> c -> Result p q c j

    Advances a dissection by filling in the intermediary structure q c j with some value c.

#map Source

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

A tail-recursive map operation, implemented in terms of Dissect.

#traverse Source

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

A tail-recursive traverse operation, implemented in terms of Dissect.

Derived from: https://blog.functorial.com/posts/2017-06-18-Stack-Safe-Traversals-via-Dissection.html

#sequence Source

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

A tail-recursive sequence operation, implemented in terms of Dissect.