unfoldable-0.4.0: Class of data structures that can be unfolded.

Portabilitynon-portable
Stabilityexperimental
Maintainersjoerd@w3future.com
Safe HaskellNone

Data.Unfolder

Contents

Description

Unfolders provide a way to unfold data structures. They are applicative functors that can perform a choice. (Which is basically Alternative without empty.)

Synopsis

Unfolder

class Applicative f => Unfolder f whereSource

Unfolders provide a way to unfold data structures. The minimal implementation is choose.

Methods

choose :: [f x] -> f xSource

Choose one of the values from the list.

chooseInt :: Int -> f IntSource

Given a number n, return a number between '0' and 'n - 1'.

Instances

Unfolder []

Don't choose but return all items.

Unfolder Right

Always choose the last item.

Unfolder Left

Always choose the first item.

Unfolder m => Unfolder (Reverse m) 
Applicative f => Unfolder (BFS f)

Choose between values of a given depth only.

(Monad m, Unfolder m) => Unfolder (StateT s m) 
Unfolder m => Unfolder (ReaderT r m) 
Unfolder m => Unfolder (ContT r m) 
(Unfolder p, Applicative q) => Unfolder (Compose p q) 
(Unfolder p, Unfolder q) => Unfolder (Product p q) 
(Functor m, Monad m, RandomGen g) => Unfolder (Random g m)

Choose randomly.

chooseAltDefault :: (Alternative f, Unfolder f) => [f x] -> f xSource

If an unfolder is an instance of Alternative, choose can be implemented in terms of <|>.

chooseMonadDefault :: (Monad m, Unfolder m) => [m x] -> m xSource

If an unfolder is monadic, choose can be implemented in terms of chooseInt.

boundedEnum :: forall f a. (Unfolder f, Bounded a, Enum a) => f aSource

If a datatype is bounded and enumerable, we can use chooseInt to generate a value.

Unfolder instances

newtype Left x Source

Constructors

L 

Fields

getL :: Identity x
 

Instances

Monad Left 
Functor Left 
Applicative Left 
Unfolder Left

Always choose the first item.

newtype Right x Source

Constructors

R 

Fields

getR :: Identity x
 

Instances

Monad Right 
Functor Right 
Applicative Right 
Unfolder Right

Always choose the last item.

newtype Random g m a Source

Constructors

Random 

Fields

getRandom :: StateT g m a
 

Instances

Monad m => Monad (Random g m) 
Functor m => Functor (Random g m) 
(Monad m, Functor m) => Applicative (Random g m) 
(Functor m, Monad m, RandomGen g) => Unfolder (Random g m)

Choose randomly.

newtype BFS f x Source

Return a generator of values of a given depth. Returns Nothing if there are no values of that depth or deeper.

Constructors

BFS 

Fields

getBFS :: Int -> Maybe [f x]
 

Instances

Functor f => Functor (BFS f) 
Applicative f => Applicative (BFS f) 
Applicative f => Unfolder (BFS f)

Choose between values of a given depth only.

runBFS :: Unfolder f => BFS f x -> f xSource

packBFS :: f x -> BFS f xSource