-- 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.5.1 -- | 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 :: * -> * cons = mplus . return runList :: List l => l a -> ItemM l (ListItem l a) joinL :: List l => ItemM l (l a) -> l a cons :: List l => a -> 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 -- | Convert a list to a MonadPlus -- --
-- > fromList [] :: Maybe Int -- Nothing -- > fromList [5] :: Maybe Int -- Just 5 --fromList :: List l => [a] -> l a -- | filter for any MonadPlus -- --
-- > filter (> 5) (Just 3) -- Nothing --filter :: MonadPlus m => (a -> Bool) -> m a -> m a repeat :: List l => a -> l a take :: List l => Int -> l a -> l 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 scanl1 :: List l => (a -> a -> a) -> l a -> 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 -- | Generalized concat -- -- For List l => l (l a) -> l a use join concat :: List l => l [a] -> l a -- | Genereralized concatMap -- -- For List l => (a -> l b) -> l a -> l b use -- =<< (monadic bind) concatMap :: List l => (a -> [b]) -> l a -> l b tail :: List l => l a -> l a enumFrom :: (List l, Enum a) => a -> l a enumFromTo :: (List l, Enum a) => a -> a -> l a catMaybes :: List l => l (Maybe a) -> l a mapMaybe :: List l => (a -> Maybe b) -> l a -> l b -- | 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 filterL :: List l => (a -> ItemM l Bool) -> l a -> l a -- | 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 repeatM :: List l => ItemM l a -> l a -- | Monadic variant of splitAt. Consumes x items from the list and return -- them with the remaining monadic list. splitAtM :: List l => Int -> l a -> ItemM l ([a], l a) -- | Monadic variant of break. Consumes items from the list until a -- condition holds. splitWhenM :: List l => (a -> ItemM l Bool) -> l a -> ItemM 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) => (ItemM l (k a) -> ItemM k (k a)) -> 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.Trans.List.Funcs (repeatM) -- import Data.List.Class (execute, scanl, takeWhile, mapL) -- import Prelude hiding (scanl, takeWhile) -- -- main = -- execute . mapL print . -- scanl (+) 0 . -- fmap (fst . head) . -- takeWhile (not . null) . -- fmap reads $ repeatM getLine --module Control.Monad.Trans.List 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) 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) -- | List functions with type limited to use ListT. This -- might come useful for type interference. -- -- Functions where the List is an input type and not only the -- result type do not need special limited versions. module Control.Monad.Trans.List.Funcs iterateM :: Monad m => (a -> m a) -> m a -> ListT m a repeatM :: Monad m => m a -> ListT m a repeat :: Monad m => a -> ListT m a fromList :: Monad m => [a] -> ListT m a