-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Class of data structures that can be unfolded from a seed value. -- -- Class of data structures that can be unfolded from a seed value. @package unfoldable @version 0.2.0 module Data.Splittable -- | Splittable datatypes are datatypes that can be used as seeds for -- unfolds. class Splittable s split :: Splittable s => Int -> s -> [s] choose :: Splittable s => [s -> x] -> s -> x getInt :: Splittable s => s -> Int -- | If a datatype is bounded and enumerable, we can use getInt to -- produce a value from a seed. boundedEnum :: (Splittable s, Bounded a, Enum a) => s -> a data Left L :: Left data Right R :: Right instance Splittable s => Splittable (Dual s) instance (Splittable a, Splittable b) => Splittable (Either a b) instance (Splittable a, Splittable b) => Splittable (a, b) instance Splittable Integer instance Splittable StdGen instance Splittable Right instance Splittable Left module Data.Unfoldable -- | Data structures that can be unfolded. -- -- For example, given a data type -- --
-- data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) ---- -- a suitable instance would be -- --
-- instance Unfoldable Tree where -- unfoldMap f = choose -- [ spread $ pure Empty -- , spread $ Leaf <$> to f -- , spread $ Node <$> to (unfoldMap f) <*> to f <*> to (unfoldMap f) -- ] ---- -- i.e. it follows closely the instance for Traversable, with -- the addition of choose, spread and to. -- -- The instance can be simplified to: -- --
-- instance Unfoldable Tree where -- unfoldMap f = choose -- [ const Empty -- , Leaf . f -- , spread $ Node <$> to (unfoldMap f) <*> to f <*> to (unfoldMap f) -- ] --class Unfoldable f unfoldMap :: (Unfoldable f, Splittable s) => (s -> a) -> s -> f a -- | The same as unfoldMap id. unfold :: (Unfoldable f, Splittable s) => s -> f s -- | Always choose the first constructor. leftMost :: Unfoldable f => f () -- | Always choose the last constructor. rightMost :: Unfoldable f => f () -- | Count the number of times to is used, and split the seed in -- that many parts. spread :: Splittable s => State ([s], Int) a -> s -> a -- | Signal to spread that this is a subpart that needs a seed. to :: (s -> a) -> State ([s], Int) a instance Unfoldable f => Unfoldable (Reverse f) instance (Unfoldable p, Unfoldable q) => Unfoldable (Compose p q) instance (Unfoldable p, Unfoldable q) => Unfoldable (Product p q) instance (Bounded a, Enum a) => Unfoldable (Constant a) instance Unfoldable Identity instance (Bounded a, Enum a) => Unfoldable ((,) a) instance (Bounded a, Enum a) => Unfoldable (Either a) instance Unfoldable Maybe instance Unfoldable []