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

Copyright(c) Sjoerd Visscher 2014
LicenseBSD-style (see the file LICENSE)
Maintainersjoerd@w3future.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell98

Data.Biunfoldable

Contents

Description

Class of data structures with 2 type arguments that can be unfolded.

Synopsis

Biunfoldable

class Biunfoldable t where Source #

Data structures with 2 type arguments (kind * -> * -> *) that can be unfolded.

For example, given a data type

data Tree a b = Empty | Leaf a | Node (Tree a b) b (Tree a b)

a suitable instance would be

instance Biunfoldable Tree where
  biunfold fa fb = choose
    [ pure Empty
    , Leaf <$> fa
    , Node <$> biunfold fa fb <*> fb <*> biunfold fa fb
    ]

i.e. it follows closely the instance for Bitraversable, but instead of matching on an input value, we choose from a list of all cases.

Methods

biunfold :: Unfolder f => f a -> f b -> f (t a b) Source #

Given a way to generate elements, return a way to generate structures containing those elements.

Instances
Biunfoldable Either Source # 
Instance details

Defined in Data.Biunfoldable

Methods

biunfold :: Unfolder f => f a -> f b -> f (Either a b) Source #

Biunfoldable (,) Source # 
Instance details

Defined in Data.Biunfoldable

Methods

biunfold :: Unfolder f => f a -> f b -> f (a, b) Source #

Biunfoldable (Constant :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Biunfoldable

Methods

biunfold :: Unfolder f => f a -> f b -> f (Constant a b) Source #

biunfold_ :: (Biunfoldable t, Unfolder f) => f (t () ()) Source #

Unfold the structure, always using () as elements.

biunfoldBF :: (Biunfoldable t, Unfolder f) => f a -> f b -> f (t a b) Source #

Breadth-first unfold, which orders the result by the number of choose calls.

biunfoldBF_ :: (Biunfoldable t, Unfolder f) => f (t () ()) Source #

Unfold the structure breadth-first, always using () as elements.

Specific unfolds

biunfoldr :: Biunfoldable t => (c -> Maybe (a, c)) -> (c -> Maybe (b, c)) -> c -> Maybe (t a b) Source #

biunfoldr builds a data structure from a seed value.

fromLists :: Biunfoldable t => [a] -> [b] -> Maybe (t a b) Source #

Create a data structure using the lists as input. This can fail because there might not be a data structure with the same number of element positions as the number of elements in the lists.

randomDefault :: (Random a, Random b, RandomGen g, Biunfoldable t) => g -> (t a b, g) Source #

Generate a random value, can be used as default instance for Random.

arbitraryDefault :: (Arbitrary a, Arbitrary b, Biunfoldable t) => Gen (t a b) Source #

Provides a QuickCheck generator, can be used as default instance for Arbitrary.