fmlist 0.2 → 0.3
raw patch · 2 files changed
+30/−20 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.FMList: genericLength :: (Num b) => FMList a -> b
+ Data.FMList: length :: FMList a -> Int
Files
- Data/FMList.hs +29/−19
- fmlist.cabal +1/−1
Data/FMList.hs view
@@ -29,6 +29,9 @@ , fromFoldable , null+ , length+ , genericLength+ , head , tail , last@@ -52,10 +55,10 @@ ) where import Prelude - ( (.), ($), flip, const, id, error+ ( (.), ($), ($!), flip, const, id, error , Maybe(..), maybe , Bool(..), (||), not- , Ord(..), Num(..)+ , Ord(..), Num(..), Int , Show(..), String, (++) ) import qualified Data.List as List@@ -69,7 +72,7 @@ -- nil is exported as empty from Applicative nil :: FMList a-nil = FM $ \f -> mempty+nil = FM $ \_ -> mempty singleton :: a -> FMList a singleton x = FM $ \f -> f x@@ -99,17 +102,24 @@ null :: FMList a -> Bool null = foldr (\_ _ -> False) True +length :: FMList a -> Int+length = genericLength++genericLength :: Num b => FMList a -> b+genericLength l = getSum $ unFM l (const $ Sum 1)++ head :: FMList a -> a head l = getFirst (unFM l (First . Just)) `fromJustOrError` "Data.FMList.head: empty list" tail :: FMList a -> FMList a-tail l = if null l then error "Data.FMList.tail: empty list" else drop 1 l+tail l = if null l then error "Data.FMList.tail: empty list" else drop (1::Int) l last :: FMList a -> a last l = getLast (unFM l (Last . Just)) `fromJustOrError` "Data.FMList.last: empty list" init :: FMList a -> FMList a-init l = if null l then error "Data.FMList.init: empty list" else reverse . drop 1 . reverse $ l+init l = if null l then error "Data.FMList.init: empty list" else reverse . drop (1::Int) . reverse $ l reverse :: FMList a -> FMList a reverse l = FM $ \f -> getDual $ unFM l (Dual . f)@@ -138,7 +148,7 @@ zipWith :: (a -> b -> c) -> FMList a -> FMList b -> FMList c zipWith t l1 l2 = FM $ \f -> foldr (\e1 r r2 -> - foldr (\e2 _ -> mappend (f (t e1 e2)) (r (drop 1 r2))) mempty r2) (const mempty) l1 l2+ foldr (\e2 _ -> mappend (f (t e1 e2)) (r (drop (1::Int) r2))) mempty r2) (const mempty) l1 l2 zip :: FMList a -> FMList b -> FMList (a,b) zip = zipWith (,)@@ -162,36 +172,36 @@ instance Functor FMList where- fmap g c = FM $ \f -> unFM c (f . g)+ fmap g c = FM $ \f -> unFM c (f . g) instance Foldable FMList where- foldMap = flip unFM+ foldMap = flip unFM instance Traversable FMList where traverse f = foldr cons_f (pure empty) where cons_f x ys = cons <$> f x <*> ys instance Monad FMList where- return = singleton- m >>= g = FM $ \f -> unFM m (foldMap f . g)+ return = singleton+ m >>= g = FM $ \f -> unFM m (foldMap f . g) instance Applicative FMList where- pure = return- (<*>) = ap+ pure = return+ gs <*> xs = FM $ \f -> unFM gs (\g -> unFM xs (f . g)) instance Monoid (FMList a) where- mempty = nil- mappend = append+ mempty = nil+ mappend = append instance MonadPlus FMList where- mzero = nil- mplus = append+ mzero = nil+ mplus = append instance Alternative FMList where- empty = nil- (<|>) = append+ empty = nil+ (<|>) = append instance Show a => Show (FMList a) where- show l = case show (toList l) of s@(_:_) -> "fromList " ++ s+ show l = "fromList " ++ (show $! toList l) fromJustOrError :: Maybe a -> String -> a
fmlist.cabal view
@@ -1,5 +1,5 @@ name: fmlist-version: 0.2+version: 0.3 synopsis: FoldMap lists description: FoldMap lists are lists represented by their foldMap function.