-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | List monad transformer and class -- -- A List monad transformer and a List class. With standard list -- operations for Lists @package List @version 0.4.0 -- | The List class and actions for lists module Data.List.Class -- | A class for list types. Every list has an underlying monad. class (MonadPlus l, Monad (ItemM l)) => List l where { type family ItemM l :: * -> *; } runList :: List l => l a -> ItemM l (ListItem l a) joinL :: List l => ItemM l (l a) -> l a data ListItem l a Nil :: ListItem l a Cons :: a -> l a -> ListItem l a headL :: ListItem l a -> a tailL :: ListItem l a -> l a -- | Prepend an item to a MonadPlus cons :: MonadPlus m => a -> m a -> m a -- | Convert a list to a MonadPlus -- --
-- > fromList [] :: Maybe Int -- Nothing -- > fromList [5] :: Maybe Int -- Just 5 --fromList :: MonadPlus m => [a] -> m a -- | filter for any MonadPlus -- --
-- > filter (> 5) (Just 3) -- Nothing --filter :: MonadPlus m => (a -> Bool) -> m a -> m a repeat :: MonadPlus m => a -> m a takeWhile :: List l => (a -> Bool) -> l a -> l a genericTake :: (Integral i, List l) => i -> l a -> l a scanl :: List l => (a -> b -> a) -> a -> l b -> l a transpose :: List l => l (l a) -> l (l a) zip :: List l => l a -> l b -> l (a, b) zipWith :: List l => (a -> b -> c) -> l a -> l b -> l c -- | foldr for Lists. the result and 'right side' values are monadic -- actions. foldrL :: List l => (a -> ItemM l b -> ItemM l b) -> ItemM l b -> l a -> ItemM l b -- | An action to do foldl for Lists foldlL :: List l => (a -> b -> a) -> a -> l b -> ItemM l a foldl1L :: List l => (a -> a -> a) -> l a -> ItemM l a -- | An action to transform a List to a list -- --
-- > runIdentity $ toList "hello!" -- "hello!" --toList :: List l => l a -> ItemM l [a] -- | Consume a list (execute its actions) and return its length -- --
-- > runIdentity $ lengthL [1,2,3] -- 3 --lengthL :: (Integral i, List l) => l a -> ItemM l i -- | Consume all items and return the last one -- --
-- > runIdentity $ lastL "hello" -- 'o' --lastL :: List l => l a -> ItemM l a -- | Merge two lists sorted by a criteria given the criteria -- --
-- > merge2On id "01568" "239" -- "01235689" --merge2On :: (Ord b, List l) => (a -> b) -> l a -> l a -> l a -- | Merge many lists sorted by a criteria given the criteria -- --
-- > mergeOn length [["hi", "hey", "hello"], ["cat", "falcon"], ["banana", "cucumber"]] -- ["hi","cat","hey","hello","banana","falcon","cucumber"] --mergeOn :: (Ord b, List l) => (a -> b) -> l (l a) -> l a -- | Execute the monadic actions in a List execute :: List l => l a -> ItemM l () -- | Transform a list of actions to a list of their results -- --
-- > joinM [Identity 4, Identity 7] -- [4,7] --joinM :: List l => l (ItemM l a) -> l a mapL :: List l => (a -> ItemM l b) -> l a -> l b -- | Monadic version of iterate. Can be used to produce trees given a -- children of node function. -- --
-- import Data.List.Tree (bfsLayers) -- take 3 $ bfsLayers (iterateM (\i -> [i*2, i*2+1]) [1] :: ListT [] Int) -- [[1],[2,3],[4,5,6,7]] --iterateM :: List l => (a -> ItemM l a) -> ItemM l a -> l a takeWhileM :: List l => (a -> ItemM l Bool) -> l a -> l a sortOn :: Ord b => (a -> b) -> [a] -> [a] -- | Transform the underlying monad of a list given a way to transform the -- monad -- --
-- > import Data.List.Tree (bfs) -- > bfs (transformListMonad (\(Identity x) -> [x, x]) "hey" :: ListT [] Char) -- "hheeeeyyyyyyyy" --transformListMonad :: (List l, List k) => (forall x. ItemM l x -> ItemM k x) -> l a -> k a -- | listStateJoin can transform a ListT (StateT s m) a to a -- StateT s m (ListT m a). -- -- When iterating a list, a state is already maintained and passed along -- in the form of the location along the list. This joins the inner -- StateT s into the list. The list will fork the state given to -- it and won't share its changes. listStateJoin :: (List l, List k, (ItemM l) ~ (StateT s (ItemM k))) => l a -> ItemM l (k a) instance (Eq a, Eq (l a)) => Eq (ListItem l a) instance (Ord a, Ord (l a)) => Ord (ListItem l a) instance (Read a, Read (l a)) => Read (ListItem l a) instance (Show a, Show (l a)) => Show (ListItem l a) instance Functor m => Functor (ListItem m) instance List [] -- | A list monad transformer / a monadic list. -- -- Monadic list example: A program which reads numbers from the user and -- accumulates them. -- --
-- import Control.Monad (join) -- import Control.Monad.ListT (ListT) -- import Control.Monad.Trans (lift) -- import Data.List.Class (execute, repeat, scanl, takeWhile, mapL) -- import Prelude hiding (repeat, scanl, takeWhile) -- -- main = -- execute . mapL print . -- scanl (+) 0 . -- fmap (fst . head) . -- takeWhile (not . null) . -- fmap reads $ do -- repeat () -- lift getLine :: ListT IO String --module Control.Monad.ListT newtype ListT m a ListT :: m (ListItem (ListT m) a) -> ListT m a runListT :: ListT m a -> m (ListItem (ListT m) a) instance Show (m (ListItem (ListT m) a)) => Show (ListT m a) instance Read (m (ListItem (ListT m) a)) => Read (ListT m a) instance Ord (m (ListItem (ListT m) a)) => Ord (ListT m a) instance Eq (m (ListItem (ListT m) a)) => Eq (ListT m a) instance MonadIO m => MonadIO (ListT m) instance Monad m => List (ListT m) instance MonadTrans ListT instance Monad m => MonadPlus (ListT m) instance Monad m => Applicative (ListT m) instance Monad m => Monad (ListT m) instance Monad m => Functor (ListT m) instance Monad m => Monoid (ListT m a)