Portability | non-portable |
---|---|

Stability | experimental |

Maintainer | sjoerd@w3future.com |

Safe Haskell | Safe-Infered |

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

- class Triunfoldable t where
- triunfold_ :: (Triunfoldable t, Unfolder f) => f (t () () ())
- triunfoldBF :: (Triunfoldable t, Unfolder f) => f a -> f b -> f c -> f (t a b c)
- triunfoldBF_ :: (Triunfoldable t, Unfolder f) => f (t () () ())
- triunfoldr :: Triunfoldable t => (d -> Maybe (a, d)) -> (d -> Maybe (b, d)) -> (d -> Maybe (c, d)) -> d -> Maybe (t a b c)
- fromLists :: Triunfoldable t => [a] -> [b] -> [c] -> Maybe (t a b c)
- randomDefault :: (Random a, Random b, Random c, RandomGen g, Triunfoldable t) => g -> (t a b c, g)
- arbitraryDefault :: (Arbitrary a, Arbitrary b, Arbitrary c, Triunfoldable t) => Gen (t a b c)

# Triunfoldable

class Triunfoldable t whereSource

Data structures with 3 type arguments (kind `* -> * -> * -> *`

) that can be unfolded.

For example, given a data type

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

a suitable instance would be

instance Triunfoldable Tree where triunfold fa fb fc = choose [ pure Empty , Leaf <$> fa , Node <$> triunfold fa fb fc <*> fb <*> triunfold fa fb fc ]

i.e. it follows closely the instance for `Biunfoldable`

, but for 3 type arguments instead of 2.

triunfold_ :: (Triunfoldable t, Unfolder f) => f (t () () ())Source

Unfold the structure, always using `()`

as elements.

triunfoldBF :: (Triunfoldable t, Unfolder f) => f a -> f b -> f c -> f (t a b c)Source

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

calls.

triunfoldBF_ :: (Triunfoldable t, Unfolder f) => f (t () () ())Source

Unfold the structure breadth-first, always using `()`

as elements.

## Specific unfolds

triunfoldr :: Triunfoldable t => (d -> Maybe (a, d)) -> (d -> Maybe (b, d)) -> (d -> Maybe (c, d)) -> d -> Maybe (t a b c)Source

`triunfoldr`

builds a data structure from a seed value.

fromLists :: Triunfoldable t => [a] -> [b] -> [c] -> Maybe (t a b c)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, Random c, RandomGen g, Triunfoldable t) => g -> (t a b c, g)Source

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

.

arbitraryDefault :: (Arbitrary a, Arbitrary b, Arbitrary c, Triunfoldable t) => Gen (t a b c)Source

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

.