packages feed

List 0.4.1 → 0.4.2

raw patch · 3 files changed

+40/−17 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Data.List.Class: enumFrom :: (List l, Enum a) => a -> l a
+ Data.List.Class: enumFromTo :: (List l, Enum a) => a -> a -> l a
+ Data.List.Class: filterL :: List l => (a -> ItemM l Bool) -> l a -> l a
+ Data.List.Class: tail :: List l => l a -> l a
- Data.List.Class: class (MonadPlus l, Monad (ItemM l)) => List l where { type family ItemM l :: * -> *; }
+ Data.List.Class: class (MonadPlus l, Monad (ItemM l)) => List l where { type family ItemM l :: * -> *; { cons = mplus . return } }
- Data.List.Class: cons :: MonadPlus m => a -> m a -> m a
+ Data.List.Class: cons :: List l => a -> l a -> l a
- Data.List.Class: fromList :: MonadPlus m => [a] -> m a
+ Data.List.Class: fromList :: List l => [a] -> l a
- Data.List.Class: repeat :: MonadPlus m => a -> m a
+ Data.List.Class: repeat :: List l => a -> l a

Files

List.cabal view
@@ -1,5 +1,5 @@ Name:                List-Version:             0.4.1+Version:             0.4.2 Category:            Control Synopsis:            List monad transformer and class Description:
src/Control/Monad/Trans/List.hs view
@@ -41,11 +41,6 @@     where         step x = return . consFunc x . joinL --- like generic cons except using that one--- would cause an infinite loop-cons :: Monad m => a -> ListT m a -> ListT m a-cons x = ListT . return . Cons x- instance Monad m => Monoid (ListT m a) where     mempty = ListT $ return Nil     mappend = flip (foldrL' cons)@@ -72,6 +67,7 @@     type ItemM (ListT m) = m     runList = runListT     joinL = ListT . (>>= runList)+    cons x = ListT . return . Cons x  instance MonadIO m => MonadIO (ListT m) where     liftIO = lift . liftIO
src/Data/List/Class.hs view
@@ -5,17 +5,21 @@ module Data.List.Class (     -- | The List typeclass     List (..), ListItem (..),+    fromList,     -- | List operations for MonadPlus-    cons, fromList, filter, repeat,+    filter,     -- | Standard list operations+    repeat,     takeWhile, genericTake, scanl, scanl1,     transpose, zip, zipWith,     concat, concatMap,+    tail,+    enumFrom, enumFromTo,     -- | Non standard List operations     foldrL, foldlL, foldl1L, toList, lengthL, lastL,     merge2On, mergeOn,     -- | Operations useful for monadic lists-    execute, joinM, mapL, iterateM, takeWhileM, repeatM,+    execute, joinM, mapL, filterL, iterateM, takeWhileM, repeatM,     -- | Operations for non-monadic lists     sortOn,     -- | Convert between List types@@ -31,13 +35,16 @@ import Data.Maybe (fromJust) import Data.Ord (comparing) import Prelude hiding (-    concat, concatMap, filter, repeat, scanl, scanl1, takeWhile, zip, zipWith)+    concat, concatMap, enumFrom, enumFromTo, filter, repeat, scanl, scanl1,+    tail, takeWhile, zip, zipWith)  data ListItem l a =     Nil |     Cons { headL :: a, tailL :: l a }     deriving (Eq, Ord, Read, Show) +infixr 5 `cons`+ -- | A class for list types. -- Every list has an underlying monad. class (MonadPlus l, Monad (ItemM l)) => List l where@@ -48,12 +55,16 @@     -- > > joinL $ Identity "hello"     -- > "hello"     joinL :: ItemM l (l a) -> l a+    -- | cons. Can be derived from MonadPlus but is part of class for performance.+    cons :: a -> l a -> l a+    cons = mplus . return  instance List [] where     type ItemM [] = Identity     runList [] = Identity Nil     runList (x:xs) = Identity $ Cons x xs     joinL = runIdentity+    cons = (:)  instance Functor m => Functor (ListItem m) where     fmap _ Nil = Nil@@ -84,19 +95,14 @@     where         onCons x = consFunc x . foldrL consFunc nilFunc -infixr 5 `cons`--- | Prepend an item to a 'MonadPlus'-cons :: MonadPlus m => a -> m a -> m a-cons = mplus . return- -- | Convert a list to a 'MonadPlus' -- -- > > fromList [] :: Maybe Int -- > Nothing -- > > fromList [5] :: Maybe Int -- > Just 5-fromList :: MonadPlus m => [a] -> m a-fromList = foldr (mplus . return) mzero+fromList :: List l => [a] -> l a+fromList = foldr cons mzero  -- | filter for any MonadPlus --@@ -161,6 +167,16 @@ repeatM :: List l => ItemM l a -> l a repeatM = joinM . repeat +filterL :: List l => (a -> ItemM l Bool) -> l a -> l a+filterL cond =+    joinL . foldrL step (return mzero)+    where+        step x rest = do+            b <- cond x+            if b+                then return . cons x . joinL $ rest+                else rest+ takeWhileM :: List l => (a -> ItemM l Bool) -> l a -> l a takeWhileM cond =     joinL . foldrL step (return mzero)@@ -213,6 +229,9 @@ zipWith :: List l => (a -> b -> c) -> l a -> l b -> l c zipWith func as = liftM (uncurry func) . zip as +tail :: List l => l a -> l a+tail = joinL . liftM tailL . runList+ -- | Consume all items and return the last one -- -- > > runIdentity $ lastL "hello"@@ -220,7 +239,7 @@ lastL :: List l => l a -> ItemM l a lastL = liftM fromJust . foldlL (const Just) Nothing -repeat :: MonadPlus m => a -> m a+repeat :: List l => a -> l a repeat = fix . cons  transpose :: List l => l (l a) -> l (l a)@@ -307,3 +326,11 @@ -- For @List l => (a -> l b) -> l a -> l b@ use '=<<' (monadic bind) concatMap :: List l => (a -> [b]) -> l a -> l b concatMap f = concat . liftM f++enumFrom :: (List l, Enum a) => a -> l a+enumFrom x = cons x (enumFrom (succ x))++enumFromTo :: (List l, Enum a) => a -> a -> l a+enumFromTo from to+    | fromEnum from > fromEnum to = mzero+    | otherwise = cons from (enumFromTo (succ from) to)