Portability  nonportable 

Stability  experimental 
Maintainer  sjoerd@w3future.com 
Safe Haskell  Trustworthy 
Unfolders provide a way to unfold data structures.
They are basically Alternative
instances, but the choose
method
allows the unfolder to do something special for the recursive positions
of the data structure.
 class Alternative f => Unfolder f where
 chooseMonadDefault :: (Monad m, Unfolder m) => [m x] > m x
 between :: (Unfolder f, Enum a) => a > a > f a
 betweenD :: (Unfolder f, Enum a) => a > a > f a
 boundedEnum :: (Unfolder f, Bounded a, Enum a) => f a
 boundedEnumD :: (Unfolder f, Bounded a, Enum a) => f a
 newtype Random g m a = Random {}
 data Arb a = Arb Int (StdGen > Int > Maybe a)
 arbUnit :: Arbitrary a => Arb a
 newtype NumConst a x = NumConst {
 getNumConst :: a
 class UnfolderTransformer t where
 ala :: (UnfolderTransformer t, Unfolder f) => (t f b > f b) > (t f a > t f b) > f a > f b
 ala2 :: (UnfolderTransformer t, Unfolder f) => (t f c > f c) > (t f a > t f b > t f c) > f a > f b > f c
 ala3 :: (UnfolderTransformer t, Unfolder f) => (t f d > f d) > (t f a > t f b > t f c > t f d) > f a > f b > f c > f d
 newtype DualA f a = DualA {
 getDualA :: f a
 data NT f g = NT {
 getNT :: forall a. f a > g a
 newtype WithRec f a = WithRec {
 getWithRec :: ReaderT (Int > NT f f) f a
 withRec :: (Int > NT f f) > WithRec f a > f a
 limitDepth :: Unfolder f => Int > WithRec f a > f a
 newtype BFS f x = BFS {}
 type Split = Int > [(Int, Int)]
 bfs :: Unfolder f => BFS f x > f x
 bfsBySum :: Unfolder f => BFS f x > f x
Unfolder
class Alternative f => Unfolder f whereSource
Unfolders provide a way to unfold data structures.
The methods have default implementations in terms of Alternative
,
but you can implement choose
to act on recursive positions of the
data structure, or simply to provide a faster implementation than asum
.
Choose one of the values from the list.
chooseInt :: Int > f IntSource
Given a number n
, return a number between '0' and 'n  1'.
Unfolder []  Don't choose but return all items. 
Unfolder Maybe  Always choose the first item. 
Unfolder Arb  Limit the depth of the generated data structure by dividing the given size by the number of recursive positions. 
MonadPlus m => Unfolder (WrappedMonad m)  Derived instance. 
Unfolder f => Unfolder (Reverse f)  Derived instance. 
Unfolder f => Unfolder (Backwards f)  Derived instance. 
Unfolder f => Unfolder (Lift f)  Derived instance. 
(Functor m, Monad m) => Unfolder (MaybeT m)  Derived instance. 
Applicative f => Unfolder (ListT f)  Derived instance. 
Num a => Unfolder (NumConst a)  Unfolds to a constant numeric value. Useful for counting shapes. 
Applicative f => Unfolder (BFS f)  Choose between values of a given depth only. 
Unfolder f => Unfolder (WithRec f)  Applies a certain function depending on the depth at every recursive position. 
Unfolder f => Unfolder (DualA f)  Reverse the list passed to choose. 
(ArrowZero a, ArrowPlus a) => Unfolder (WrappedArrow a b)  Derived instance. 
(Monoid w, Unfolder m) => Unfolder (WriterT w m)  Derived instance. 
(MonadPlus m, Unfolder m) => Unfolder (StateT s m)  Derived instance. 
Unfolder m => Unfolder (ReaderT r m)  Derived instance. 
(Functor m, Monad m, Error e) => Unfolder (ErrorT e m)  Derived instance. 
(Unfolder p, Applicative q) => Unfolder (Compose p q)  Derived instance. 
(Unfolder p, Unfolder q) => Unfolder (Product p q)  Derived instance. 
(Functor m, Monad m, RandomGen g) => Unfolder (Random g m)  Choose randomly. 
(Monoid w, MonadPlus m, Unfolder m) => Unfolder (RWST r w s m)  Derived instance. 
chooseMonadDefault :: (Monad m, Unfolder m) => [m x] > m xSource
between :: (Unfolder f, Enum a) => a > a > f aSource
If a datatype is enumerable, we can use chooseInt
to generate a value.
This is the function to use if you want to unfold a datatype that has no type arguments (has kind *
).
boundedEnum :: (Unfolder f, Bounded a, Enum a) => f aSource
If a datatype is also bounded, we choose between all possible values.
boundedEnum = between minBound maxBound
boundedEnumD :: (Unfolder f, Bounded a, Enum a) => f aSource
boundedEnumD = betweenD minBound maxBound
Unfolder instances
Monad m => Monad (Random g m)  
Functor m => Functor (Random g m)  
(Functor m, Monad m, RandomGen g) => MonadPlus (Random g m)  
(Monad m, Functor m) => Applicative (Random g m)  
(Functor m, Monad m, RandomGen g) => Alternative (Random g m)  
(Functor m, Monad m, RandomGen g) => Unfolder (Random g m)  Choose randomly. 
A variant of Test.QuickCheck.Gen, with failure and a count of the number of recursive positions.
Functor Arb  
Applicative Arb  
Alternative Arb  
Unfolder Arb  Limit the depth of the generated data structure by dividing the given size by the number of recursive positions. 
Variant of Constant
that does multiplication of the constants for <*>
and addition for <>
.
NumConst  

UnfolderTransformer
class UnfolderTransformer t whereSource
An UnfolderTransformer
changes the way an Unfolder
unfolds.
ala :: (UnfolderTransformer t, Unfolder f) => (t f b > f b) > (t f a > t f b) > f a > f bSource
Run an unfolding function with one argument using an UnfolderTransformer
, given a way to run the transformer.
ala2 :: (UnfolderTransformer t, Unfolder f) => (t f c > f c) > (t f a > t f b > t f c) > f a > f b > f cSource
Run an unfolding function with two arguments using an UnfolderTransformer
, given a way to run the transformer.
ala3 :: (UnfolderTransformer t, Unfolder f) => (t f d > f d) > (t f a > t f b > t f c > t f d) > f a > f b > f c > f dSource
Run an unfolding function with three arguments using an UnfolderTransformer
, given a way to run the transformer.
UnfolderTransformer instances
DualA
flips the <>
operator from Alternative
.
UnfolderTransformer DualA  
Functor f => Functor (DualA f)  
Applicative f => Applicative (DualA f)  
Alternative f => Alternative (DualA f)  
Unfolder f => Unfolder (DualA f)  Reverse the list passed to choose. 
Eq (f a) => Eq (DualA f a)  
Show (f a) => Show (DualA f a) 
WithRec  

UnfolderTransformer WithRec  
Functor f => Functor (WithRec f)  
Applicative f => Applicative (WithRec f)  
Alternative f => Alternative (WithRec f)  
Unfolder f => Unfolder (WithRec f)  Applies a certain function depending on the depth at every recursive position. 
withRec :: (Int > NT f f) > WithRec f a > f aSource
Apply a certain function of type f a > f a
to the result of a choose
.
The depth is passed as Int
, so you can apply a different function at each depth.
Because of a forall
, the function needs to be wrapped in a NT
constructor.
See limitDepth
for an example how to use this function.
limitDepth :: Unfolder f => Int > WithRec f a > f aSource
Limit the depth of an unfolding.
Return a generator of values of a given depth.
Returns Nothing
if there are no values of that depth or deeper.
The depth is the number of choose
calls.
UnfolderTransformer BFS  
Functor f => Functor (BFS f)  
Applicative f => Applicative (BFS f)  
Applicative f => Alternative (BFS f)  
Applicative f => Unfolder (BFS f)  Choose between values of a given depth only. 