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

Safe HaskellNone

Data.Unfolder

Synopsis

Documentation

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) 
(Alternative f, Unfolder 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.

chooseDefault :: (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.

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) 
Alternative f => Applicative (BFS f) 
(Alternative f, Unfolder f) => Unfolder (BFS f)

Choose between values of a given depth only.

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

packBFS :: f x -> BFS f xSource