ListLike 4.6.3 → 4.7
raw patch · 20 files changed
+235/−90 lines, 20 filesdep ~basedep ~bytestringdep ~containersPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, bytestring, containers, utf8-string
API changes (from Hackage documentation)
- Data.ListLike.Vector.Generic: instance (GHC.Base.Monoid (v a), GHC.Classes.Eq (v a), Data.Vector.Generic.Base.Vector v a) => Data.ListLike.Base.ListLike (v a) a
+ Data.ListLike: fromLazyText :: (StringLike s, StringLike Text) => Text -> s
+ Data.ListLike: fromStringLike :: (StringLike s, StringLike s') => s -> s'
+ Data.ListLike: fromText :: (StringLike s, StringLike Text) => Text -> s
+ Data.ListLike: show :: (StringLike s, Show a) => a -> s
+ Data.ListLike: type ListOps full = (ListLike full (Item full))
+ Data.ListLike.Base: fromList' :: ListLike full item => [item] -> full
+ Data.ListLike.Base: toList' :: ListLike full item => full -> [item]
+ Data.ListLike.Base: type ListOps full = (ListLike full (Item full))
+ Data.ListLike.CharString: instance Data.String.IsString Data.ListLike.CharString.CharString
+ Data.ListLike.CharString: instance Data.String.IsString Data.ListLike.CharString.CharStringLazy
+ Data.ListLike.CharString: instance GHC.Exts.IsList Data.ListLike.CharString.CharString
+ Data.ListLike.CharString: instance GHC.Exts.IsList Data.ListLike.CharString.CharStringLazy
+ Data.ListLike.Chars: instance GHC.Exts.IsList Data.ListLike.Chars.Chars
+ Data.ListLike.FMList: instance GHC.Exts.IsList (Data.FMList.FMList a)
+ Data.ListLike.Instances: instance (GHC.Real.Integral i, GHC.Arr.Ix i) => Data.String.IsString (GHC.Arr.Array i GHC.Types.Char)
+ Data.ListLike.Instances: instance (GHC.Real.Integral i, GHC.Arr.Ix i) => GHC.Exts.IsList (GHC.Arr.Array i e)
+ Data.ListLike.Instances: instance GHC.Exts.IsList Data.ByteString.Internal.ByteString
+ Data.ListLike.Instances: instance GHC.Exts.IsList Data.ByteString.Lazy.Internal.ByteString
+ Data.ListLike.String: fromLazyText :: (StringLike s, StringLike Text) => Text -> s
+ Data.ListLike.String: fromStringLike :: (StringLike s, StringLike s') => s -> s'
+ Data.ListLike.String: fromText :: (StringLike s, StringLike Text) => Text -> s
+ Data.ListLike.String: show :: (StringLike s, Show a) => a -> s
+ Data.ListLike.Text.Builder: instance GHC.Exts.IsList Data.Text.Internal.Builder.Builder
+ Data.ListLike.UTF8: instance Data.String.IsString (Data.String.UTF8.UTF8 Data.ByteString.Internal.ByteString)
+ Data.ListLike.UTF8: instance Data.String.IsString (Data.String.UTF8.UTF8 Data.ByteString.Lazy.Internal.ByteString)
+ Data.ListLike.UTF8: instance GHC.Exts.IsList (Data.String.UTF8.UTF8 Data.ByteString.Internal.ByteString)
+ Data.ListLike.UTF8: instance GHC.Exts.IsList (Data.String.UTF8.UTF8 Data.ByteString.Lazy.Internal.ByteString)
+ Data.ListLike.Vector.Generic: instance (GHC.Classes.Eq (v GHC.Types.Char), Data.Vector.Generic.Base.Vector v GHC.Types.Char) => Data.String.IsString (v GHC.Types.Char)
+ Data.ListLike.Vector.Generic: instance (GHC.Exts.IsList (v a), GHC.Exts.Item (v a) Data.Type.Equality.~ a, GHC.Base.Monoid (v a), GHC.Classes.Eq (v a), Data.Vector.Generic.Base.Vector v a) => Data.ListLike.Base.ListLike (v a) a
+ Data.ListLike.Vector.Storable: instance Data.String.IsString (Data.Vector.Storable.Vector GHC.Types.Char)
+ Data.ListLike.Vector.Unboxed: instance Data.String.IsString (Data.Vector.Unboxed.Base.Vector GHC.Types.Char)
+ Data.ListLike.Vector.Vector: instance Data.String.IsString (Data.Vector.Vector GHC.Types.Char)
- Data.ListLike: class (FoldableLL full item, Monoid full) => ListLike full item | full -> item
+ Data.ListLike: class (IsList full, item ~ Item full, FoldableLL full item, Monoid full) => ListLike full item | full -> item
- Data.ListLike: class StringLike s
+ Data.ListLike: class IsString s => StringLike s
- Data.ListLike: fromList :: ListLike full item => [item] -> full
+ Data.ListLike: fromList :: IsList l => [Item l] -> l
- Data.ListLike: fromString :: StringLike s => String -> s
+ Data.ListLike: fromString :: IsString a => String -> a
- Data.ListLike: toList :: ListLike full item => full -> [item]
+ Data.ListLike: toList :: IsList l => l -> [Item l]
- Data.ListLike.Base: class (FoldableLL full item, Monoid full) => ListLike full item | full -> item
+ Data.ListLike.Base: class (IsList full, item ~ Item full, FoldableLL full item, Monoid full) => ListLike full item | full -> item
- Data.ListLike.Base: fromList :: ListLike full item => [item] -> full
+ Data.ListLike.Base: fromList :: IsList l => [Item l] -> l
- Data.ListLike.Base: toList :: ListLike full item => full -> [item]
+ Data.ListLike.Base: toList :: IsList l => l -> [Item l]
- Data.ListLike.String: class StringLike s
+ Data.ListLike.String: class IsString s => StringLike s
- Data.ListLike.String: fromString :: StringLike s => String -> s
+ Data.ListLike.String: fromString :: IsString a => String -> a
Files
- ListLike.cabal +2/−2
- README.md +11/−12
- src/Data/ListLike.hs +4/−3
- src/Data/ListLike/Base.hs +20/−11
- src/Data/ListLike/CharString.hs +23/−6
- src/Data/ListLike/Chars.hs +13/−2
- src/Data/ListLike/DList.hs +4/−3
- src/Data/ListLike/FMList.hs +9/−4
- src/Data/ListLike/Instances.hs +30/−13
- src/Data/ListLike/String.hs +23/−4
- src/Data/ListLike/Text/Builder.hs +10/−1
- src/Data/ListLike/Text/Text.hs +6/−3
- src/Data/ListLike/Text/TextLazy.hs +5/−3
- src/Data/ListLike/UTF8.hs +21/−6
- src/Data/ListLike/Vector/Generic.hs +16/−5
- src/Data/ListLike/Vector/Storable.hs +8/−3
- src/Data/ListLike/Vector/Unboxed.hs +8/−3
- src/Data/ListLike/Vector/Vector.hs +8/−3
- testsrc/TestInfrastructure.hs +13/−3
- testsrc/runtests.hs +1/−0
ListLike.cabal view
@@ -1,5 +1,5 @@ Name: ListLike-Version: 4.6.3+Version: 4.7 License: BSD3 Maintainer: David Fox <dsf@seereason.com> Author: John Goerzen@@ -88,4 +88,4 @@ source-repository head type: git- location: git://github.com/JohnLato/listlike.git+ location: git://github.com/ddssff/listlike.git
README.md view
@@ -1,4 +1,4 @@-[](http://travis-ci.org/JohnLato/listlike)+[](http://travis-ci.org/ddssff/ListLike) ListLike ========@@ -6,15 +6,14 @@ The `ListLike` package provides typeclasses and instances to allow polymorphism over many common datatypes. -Installation---------------The package can be built/installed with Cabal. If you have `cabal-install`,-simply run `cabal install ListLike` to install the package. Without-`cabal-install`, execute the following commands:+CHANGES+=======+Version 4.7+----------- -```-$ runghc Setup.hs configure-$ runghc Setup.hs build-$ runghc Setup.hs install-```+ * Make `GHC.Exts.IsList` a superclass of `ListLike` and use its `fromList` and `toList` methods+ * make `Data.String.IsString` a superclass of `Stringlike` and use its `fromString` method+ * Add methods to `StringLike`: `show`, `fromText`, `fromLazyText`+ * Add a class `ListOps`, alternative to `ListLike`, that uses the `GHC.Exts.Item` instead of+ the `item` type parameter.+ * Supply `instance IsString Seq` for old versions of container
src/Data/ListLike.hs view
@@ -72,7 +72,8 @@ ListLikeIO(..), -- * Special lists -- ** Strings- toString, fromString, lines, words,+ toString, fromString, lines, words, show,+ fromStringLike, fromText, fromLazyText, -- ** \"Set\" operations nub, delete, deleteFirsts, union, intersect, -- ** Ordered lists@@ -103,7 +104,7 @@ -- * Base Typeclasses -- ** The ListLike class- ListLike,+ ListLike, ListOps, -- ** The FoldableLL class FoldableLL, -- ** The StringLike class@@ -119,7 +120,7 @@ sequence_, mapM, mapM_, concatMap, and, or, sum, product, repeat, replicate, cycle, take, drop, splitAt, elem, notElem, unzip, lines, words,- unlines, unwords, foldMap)+ unlines, unwords, foldMap, show) import Data.ListLike.Base import Data.ListLike.Chars import Data.ListLike.CharString
src/Data/ListLike/Base.hs view
@@ -1,9 +1,11 @@ {-# LANGUAGE ScopedTypeVariables+ ,TypeFamilies ,MultiParamTypeClasses ,FunctionalDependencies ,FlexibleInstances ,BangPatterns ,FlexibleContexts+ ,ConstraintKinds ,CPP #-} {-@@ -31,7 +33,8 @@ module Data.ListLike.Base (- ListLike(..),+ ListLike(..), ListOps,+ toList, fromList, InfiniteListLike(..), zip, zipWith, sequence_ ) where@@ -48,6 +51,7 @@ import qualified Control.Monad as M import Data.Monoid import Data.Maybe+import GHC.Exts (IsList(Item, fromList, {-fromListN,-} toList)) {- | The class implementing list-like functions. @@ -67,7 +71,7 @@ * null or genericLength -}-class (FoldableLL full item, Monoid full) =>+class (IsList full, item ~ Item full, FoldableLL full item, Monoid full) => ListLike full item | full -> item where ------------------------------ Creation@@ -426,16 +430,19 @@ ------------------------------ Conversions {- | Converts the structure to a list. This is logically equivolent- to 'fromListLike', but may have a more optimized implementation. -}- toList :: full -> [item]- toList = fromListLike+ to 'fromListLike', but may have a more optimized implementation.+ These two functions are now retired in favor of the methods of+ IsList, but they are retained here because some instances still+ use this implementation. -}+ toList' :: full -> [item]+ toList' = fromListLike {- | Generates the structure from a list. -}- fromList :: [item] -> full- fromList [] = empty- fromList (x:xs) = cons x (fromList xs)+ fromList' :: [item] -> full+ fromList' [] = empty+ fromList' (x:xs) = cons x (fromList xs) - {- | Converts one ListLike to another. See also 'toList'.+ {- | Converts one ListLike to another. See also 'toList''. Default implementation is @fromListLike = map id@ -} fromListLike :: ListLike full' item => full -> full' fromListLike = map id@@ -550,6 +557,10 @@ (singleton, head, tail, genericLength) #-} #endif +-- | A version of 'ListLike' with a single type parameter, the item+-- type is obtained using the 'Item' type function from 'IsList'.+type ListOps full = (ListLike full (Item full))+ {- instance (ListLike full item) => Monad full where m >>= k = foldr (append . k) empty m@@ -601,8 +612,6 @@ rigidMap = L.map reverse = L.reverse intersperse = L.intersperse- toList = id- fromList = id -- fromListLike = toList concat = L.concat . toList -- concatMap func = fromList . L.concatMap func
src/Data/ListLike/CharString.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE MultiParamTypeClasses ,FlexibleInstances+ ,TypeFamilies ,TypeSynonymInstances #-} @@ -50,11 +51,13 @@ import Data.Int import Data.Monoid import Data.Semigroup (Semigroup(..))+import Data.String (IsString(..)) import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy.Char8 as BSL --import qualified System.IO as IO --import Data.Word import Control.Arrow+import GHC.Exts (IsList(..)) -------------------------------------------------- -- ByteString@@ -78,6 +81,11 @@ foldr f i0 ls = BS.foldr f i0 (unCS ls) foldr1 f ls = BS.foldr1 f (unCS ls) +instance IsList CharString where+ type Item CharString = Char+ toList = BS.unpack . unCS+ fromList = CS . BS.pack+ instance ListLike CharString Char where empty = CS BS.empty singleton = CS . BS.singleton@@ -135,8 +143,8 @@ --intersect = BS.intersect --sort = BS.sort --insert = BS.insert- toList = BS.unpack . unCS- fromList = CS . BS.pack+ --toList = BS.unpack . unCS+ --fromList = CS . BS.pack --fromListLike = fromList . toList --nubBy = BS.nubBy --deleteBy = BS.deleteBy@@ -170,9 +178,11 @@ writeFile fp = BS.writeFile fp . unCS appendFile fp = BS.appendFile fp . unCS +instance IsString CharString where+ fromString = CS . BS.pack+ instance StringLike CharString where toString = BS.unpack . unCS- fromString = CS . BS.pack -------------------------------------------------- -- ByteString.Lazy@@ -200,6 +210,11 @@ mi64toi Nothing = Nothing mi64toi (Just x) = Just (fromIntegral x) +instance IsList CharStringLazy where+ type Item CharStringLazy = Char+ toList = BSL.unpack . unCSL+ fromList = CSL . BSL.pack+ instance ListLike CharStringLazy Char where empty = CSL BSL.empty singleton = CSL . BSL.singleton@@ -257,8 +272,8 @@ --intersect = BSL.intersect --sort = BSL.sort --insert = BSL.insert- toList = BSL.unpack . unCSL- fromList = CSL . BSL.pack+ --toList = BSL.unpack . unCSL+ --fromList = CSL . BSL.pack --fromListLike = fromList . toList --nubBy = BSL.nubBy --deleteBy = BSL.deleteBy@@ -295,6 +310,8 @@ writeFile fp = BSL.writeFile fp . unCSL appendFile fp = BSL.appendFile fp . unCSL +instance IsString CharStringLazy where+ fromString = CSL . BSL.pack+ instance StringLike CharStringLazy where toString = BSL.unpack . unCSL- fromString = CSL . BSL.pack
src/Data/ListLike/Chars.hs view
@@ -1,6 +1,7 @@ -- | Work in progress. {-# LANGUAGE CPP ,MultiParamTypeClasses+ ,TypeFamilies ,FlexibleInstances #-} module Data.ListLike.Chars@@ -24,6 +25,7 @@ import Data.ListLike.IO import Data.ListLike.String as LL import Data.ListLike.Text ()+import GHC.Exts (IsList(..)) data Chars = B Builder.Builder@@ -43,7 +45,10 @@ mappend a b = B $ mappend (builder a) (builder b) instance String.IsString Chars where- fromString = B . String.fromString+ -- Builder already has an IsString instance, do we want to use it?+ -- fromString = B . String.fromString+ -- or do we want the implementation that used to be in the StringLike instance?+ fromString = B . Builder.fromLazyText . LL.fromString instance FoldableLL Chars Char where foldl f r0 (B b) = LL.foldl f r0 . Builder.toLazyText $ b@@ -60,6 +65,11 @@ foldr1 f (B b) = LL.foldr1 f . Builder.toLazyText $ b foldr1 f (T s) = LL.foldr1 f $ s +instance IsList Chars where+ type Item Chars = Char+ toList = LL.toList'+ fromList = LL.fromList'+ instance ListLike Chars Char where singleton = B . Builder.singleton uncons (B b) =@@ -84,7 +94,8 @@ instance StringLike Chars where toString (B b) = toString . Builder.toLazyText $ b toString (T s) = toString $ s- fromString = B . Builder.fromLazyText . LL.fromString+ fromLazyText = B . Builder.fromLazyText+ fromText = B . Builder.fromText instance NFData Chars where rnf (B b) = rnf . Builder.toLazyText $ b
src/Data/ListLike/DList.hs view
@@ -17,6 +17,7 @@ import qualified Data.String as S import Control.Category import Data.Char (Char)+import GHC.Exts (IsList(..)) instance FoldableLL (DList a) a where foldl = F.foldl@@ -36,13 +37,13 @@ tail = D.tail rigidMap = D.map null = null . D.toList- toList = D.toList- fromList = D.fromList+ --toList = D.toList+ --fromList = D.fromList replicate = D.replicate instance StringLike (DList Char) where toString = D.toList- fromString = D.fromList+ -- fromString = D.fromList lines = map D.fromList . S.lines . D.toList words = map D.fromList . S.words . D.toList unlines = D.fromList . S.unlines . map D.toList
src/Data/ListLike/FMList.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, TypeFamilies #-} {-# OPTIONS -fno-warn-orphans #-} -- | 'Data.ListLike.ListLike' instances for 'Data.FMList.FMList' module Data.ListLike.FMList () where@@ -19,6 +19,7 @@ import qualified Control.Monad.Zip as Z --import Data.Function import Data.Char (Char)+import GHC.Exts (IsList(..)) instance FoldableLL (FMList a) a where foldl = F.foldl@@ -28,6 +29,11 @@ foldl' = F.foldl' foldr' = F.foldr' +instance IsList (FMList a) where+ type Item (FMList a) = a+ fromList = FM.fromList+ toList = FM.toList+ instance ListLike (FMList a) a where empty = FM.empty singleton = FM.singleton@@ -38,8 +44,8 @@ tail = FM.tail last = FM.last init = FM.init- fromList = FM.fromList- toList = FM.toList+ --fromList = FM.fromList+ --toList = FM.toList null = FM.null genericLength = FM.genericLength length = FM.length@@ -59,7 +65,6 @@ fromString = FM.fromList instance StringLike (FMList Char) where- fromString = FM.fromList toString = FM.toList lines = map FM.fromList . S.lines . FM.toList words = map FM.fromList . S.words . FM.toList
src/Data/ListLike/Instances.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE CPP ,MultiParamTypeClasses ,FlexibleInstances+ ,TypeFamilies ,TypeSynonymInstances #-} {-# OPTIONS -fno-warn-orphans #-} @@ -63,10 +64,12 @@ import Data.Array.IArray((!), (//), Ix(..)) import qualified Data.ByteString.Lazy as BSL import qualified Data.ByteString.Lazy.Char8 as BSLC+import Data.String (IsString(fromString)) --import Data.String.UTF8 (UTF8) --import qualified Data.String.UTF8 as UTF8 import qualified System.IO as IO import Data.Word+import GHC.Exts (IsList(..)) -------------------------------------------------- -- []@@ -111,7 +114,7 @@ instance StringLike String where toString = id- fromString = id+ --fromString = id instance InfiniteListLike [a] a where iterate = L.iterate@@ -129,6 +132,11 @@ foldr' = BS.foldr' foldr1 = BS.foldr1 +instance IsList BS.ByteString where+ type Item BS.ByteString = Word8+ toList = BS.unpack+ fromList = BS.pack+ instance ListLike BS.ByteString Word8 where empty = BS.empty singleton = BS.singleton@@ -188,8 +196,6 @@ --intersect = BS.intersect sort = BS.sort --insert = BS.insert- toList = BS.unpack- fromList = BS.pack --fromListLike = fromList . toList --nubBy = BS.nubBy --deleteBy = BS.deleteBy@@ -231,7 +237,7 @@ #if 0 instance StringLike BS.ByteString where toString = BSU.toString- fromString = BSU.fromString+ --fromString = BSU.fromString #endif --------------------------------------------------@@ -249,6 +255,11 @@ mi64toi Nothing = Nothing mi64toi (Just x) = Just (fromIntegral x) +instance IsList BSL.ByteString where+ type Item BSL.ByteString = Word8+ toList = BSL.unpack+ fromList = BSL.pack+ instance ListLike BSL.ByteString Word8 where empty = BSL.empty singleton = BSL.singleton@@ -309,8 +320,6 @@ --intersect = BSL.intersect --sort = BSL.sort --insert = BSL.insert- toList = BSL.unpack- fromList = BSL.pack --fromListLike = fromList . toList --nubBy = BSL.nubBy --deleteBy = BSL.deleteBy@@ -349,7 +358,7 @@ #if 0 instance StringLike BSL.ByteString where toString = BSLU.toString- fromString = BSLU.fromString+ --fromString = BSLU.fromString #endif --------------------------------------------------@@ -387,6 +396,11 @@ newbhigh = bhigh + newlen (blow, bhigh) = A.bounds l1 +instance (Integral i, Ix i) => IsList (A.Array i e) where+ type Item (A.Array i e) = e+ toList = A.elems+ fromList l = A.listArray (0, genericLength l - 1) l+ instance (Integral i, Ix i) => ListLike (A.Array i e) e where empty = mempty singleton i = A.listArray (0, 0) [i]@@ -453,8 +467,6 @@ -- intersect sort l = A.listArray (A.bounds l) (L.sort (A.elems l)) -- insert- toList = A.elems- fromList l = A.listArray (0, genericLength l - 1) l -- fromListLike nubBy f = fromList . L.nubBy f . toList -- deleteBy@@ -480,9 +492,11 @@ (L.genericReplicate count i) +instance (Integral i, Ix i) => IsString (A.Array i Char) where+ fromString = fromList+ instance (Integral i, Ix i) => StringLike (A.Array i Char) where toString = toList- fromString = fromList -- lines -- words @@ -521,9 +535,14 @@ -- writeFile -- appendFile +#if !MIN_VERSION_containers(0,5,7)+instance IsString (S.Seq Char) where+ fromString = S.fromList+#endif+ instance StringLike (S.Seq Char) where toString = toList- fromString = fromList+ --fromString = fromList instance FoldableLL (S.Seq a) a where foldl = F.foldl@@ -589,8 +608,6 @@ --intersect = sort = S.sort --insert = S.insert- toList = F.toList- fromList = S.fromList --fromListLike = fromList . toList --nubBy = --deleteBy =
src/Data/ListLike/String.hs view
@@ -21,8 +21,11 @@ Written by John Goerzen, jgoerzen\@complete.org -} +{-# LANGUAGE FlexibleContexts #-}+ module Data.ListLike.String ( StringLike(..)+ , fromString ) where import Prelude hiding (length, head, last, null, tail, map, filter, concat,@@ -35,17 +38,17 @@ unlines, unwords) import qualified Data.List as L import Data.ListLike.Base+import Data.String+import Data.Text (Text)+import qualified Data.Text.Lazy as Lazy (Text) {- | An extension to 'ListLike' for those data types that are similar to a 'String'. Minimal complete definition is 'toString' and 'fromString'. -}-class StringLike s where+class IsString s => StringLike s where {- | Converts the structure to a 'String' -} toString :: s -> String - {- | Converts a 'String' to a list -}- fromString :: String -> s- {- | Breaks a string into a list of strings -} lines :: (ListLike full s) => s -> full --lines = map fromString . L.lines . toString@@ -62,6 +65,22 @@ {- | Joins words -} unwords :: ListLike full s => full -> s unwords = myUnwords++ {- | Generalize the 'Show' method t return any 'StringLike'. -}+ show :: Show a => a -> s+ show = fromString . Prelude.show++ fromStringLike :: StringLike s' => s -> s'+ fromStringLike = fromString . toString++ {- | Override this to avoid extra 'String' conversions. -}+ fromText :: StringLike Text => Text -> s+ fromText = fromString . toString+ {- | Override this to avoid extra 'String' conversions. -}+ fromLazyText :: StringLike Lazy.Text => Lazy.Text -> s+ fromLazyText = fromString . toString++{-# DEPRECATED fromStringLike "Use fromString . toString or something more efficient using local knowledge" #-} -- For some reason, Hugs required splitting these out into -- separate functions.
src/Data/ListLike/Text/Builder.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE CPP ,MultiParamTypeClasses+ ,TypeFamilies ,FlexibleInstances #-} {-# OPTIONS -fno-warn-orphans #-} @@ -18,11 +19,18 @@ import Data.ListLike.String as LL import Data.ListLike.Text.TextLazy () --import Data.String (IsString(fromString))+import GHC.Exts (IsList(..)) instance FoldableLL Builder.Builder Char where foldl f r0 = LL.foldl f r0 . Builder.toLazyText foldr f r0 = LL.foldr f r0 . Builder.toLazyText +instance IsList Builder.Builder where+ type Item Builder.Builder = Char+ -- Can we do better?+ toList = LL.toList'+ fromList = LL.fromList'+ instance ListLike Builder.Builder Char where singleton = Builder.singleton uncons b = case LL.uncons (Builder.toLazyText b) of@@ -39,7 +47,8 @@ instance StringLike Builder.Builder where toString = toString . Builder.toLazyText- fromString = Builder.fromLazyText . LL.fromString+ fromText = Builder.fromText+ fromLazyText = Builder.fromLazyText instance NFData Builder.Builder where rnf = rnf . Builder.toLazyText
src/Data/ListLike/Text/Text.hs view
@@ -10,6 +10,7 @@ import Control.Monad import qualified Data.Text as T import qualified Data.Text.IO as TI+import qualified Data.Text.Lazy as Lazy (toStrict) import Data.Text.Encoding (decodeUtf8) import Data.ListLike.Base as LL import Data.ListLike.FoldableLL@@ -67,8 +68,8 @@ filter = T.filter index = T.index findIndex = T.findIndex- toList = T.unpack- fromList = T.pack+ --toList = T.unpack+ --fromList = T.pack --fromListLike = fromList . toList groupBy f = fromList . T.groupBy f genericLength = fromInteger . fromIntegral . T.length@@ -98,8 +99,10 @@ instance StringLike T.Text where toString = T.unpack- fromString = T.pack words = fromList . T.words lines = fromList . T.lines unwords = T.unwords . toList unlines = T.unlines . toList++ fromText = id+ fromLazyText = Lazy.toStrict
src/Data/ListLike/Text/TextLazy.hs view
@@ -65,8 +65,8 @@ find = T.find filter = T.filter index t = T.index t . fromIntegral- toList = T.unpack- fromList = T.pack+ --toList = T.unpack+ --fromList = T.pack --fromListLike = fromList . toList groupBy f = fromList . T.groupBy f genericLength = fromInteger . fromIntegral . T.length@@ -96,8 +96,10 @@ instance StringLike T.Text where toString = T.unpack- fromString = T.pack words = fromList . T.words lines = fromList . T.lines unwords = T.unwords . toList unlines = T.unlines . toList++ fromText = T.fromStrict+ fromLazyText = id
src/Data/ListLike/UTF8.hs view
@@ -24,16 +24,17 @@ import qualified Data.ByteString.Lazy as BSL import qualified Data.ByteString.Lazy.Char8 as BSLC --import Control.DeepSeq (NFData(rnf))-import Data.ListLike.Base+import Data.ListLike.Base as LL import Data.ListLike.FoldableLL import Data.ListLike.IO import Data.ListLike.String (StringLike(..)) import Data.Maybe (fromMaybe) import Data.Monoid (Monoid(..)) import Data.Semigroup (Semigroup(..))---import Data.String (IsString(fromString))+import Data.String (IsString(fromString)) import Data.String.UTF8 (UTF8{-, UTF8Bytes-}) import qualified Data.String.UTF8 as UTF8+import GHC.Exts (IsList(..)) --import GHC.Generics #if 0@@ -49,6 +50,11 @@ -- foldr' = UTF8.foldr' -- foldr1 = UTF8.foldr1 +instance IsList (UTF8 BS.ByteString) where+ type Item (UTF8 BS.ByteString) = Char+ toList = UTF8.toString+ fromList = LL.fromList' -- LL.map id+ instance ListLike (UTF8 BS.ByteString) Char where empty = mempty singleton c = UTF8.fromString [c]@@ -108,7 +114,7 @@ -- --intersect = UTF8.intersect -- sort = UTF8.sort -- --insert = UTF8.insert- toList = UTF8.toString+ --toList = UTF8.toString -- fromList = UTF8.pack -- fromListLike = fromList . toList -- --nubBy = UTF8.nubBy@@ -141,9 +147,11 @@ -- writeFile = BS.writeFile -- appendFile = BS.appendFile +instance IsString (UTF8 BS.ByteString) where+ fromString = UTF8.fromString+ instance StringLike (UTF8 BS.ByteString) where toString = UTF8.toString- fromString = UTF8.fromString instance Semigroup (UTF8 BS.ByteString) where (<>) = mappend@@ -163,6 +171,11 @@ -- foldr' = UTF8.foldr' -- foldr1 = UTF8.foldr1 +instance IsList (UTF8 BSL.ByteString) where+ type Item (UTF8 BSL.ByteString) = Char+ toList = UTF8.toString+ fromList = LL.fromList' -- LL.map id+ instance ListLike (UTF8 BSL.ByteString) Char where empty = mempty singleton c = UTF8.fromString [c]@@ -222,7 +235,7 @@ -- --intersect = UTF8.intersect -- sort = UTF8.sort -- --insert = UTF8.insert- toList = UTF8.toString+ -- toList = UTF8.toString -- fromList = UTF8.pack -- fromListLike = fromList . toList -- --nubBy = UTF8.nubBy@@ -258,9 +271,11 @@ instance Semigroup (UTF8 BSL.ByteString) where (<>) = mappend +instance IsString (UTF8 BSL.ByteString) where+ fromString = UTF8.fromString+ instance StringLike (UTF8 BSL.ByteString) where toString = UTF8.toString- fromString = UTF8.fromString instance Monoid (UTF8 BSL.ByteString) where mempty = UTF8.fromString []
src/Data/ListLike/Vector/Generic.hs view
@@ -2,6 +2,7 @@ ,MultiParamTypeClasses ,FlexibleContexts ,FlexibleInstances+ ,TypeFamilies ,UndecidableInstances #-} #if __GLASGOW_HASKELL__ < 710 {-# LANGUAGE OverlappingInstances #-}@@ -22,8 +23,9 @@ import Data.ListLike.Base import Data.ListLike.FoldableLL import Data.ListLike.String- import Data.Monoid+import Data.String (IsString(fromString))+import GHC.Exts (IsList(..)) instance {-# OVERLAPPABLE #-} V.Vector v a => FoldableLL (v a) a where foldl = V.foldl@@ -33,7 +35,14 @@ foldr' = V.foldr' foldr1 = V.foldr1 -instance {-# OVERLAPPABLE #-} (Monoid (v a), Eq (v a), V.Vector v a) => ListLike (v a) a where+#if 0+instance {-# OVERLAPPABLE #-} (Monoid (v a), Eq (v a), V.Vector v a) => IsList (v a) where+ type Item (v a) = a+ toList = V.toList+ fromList = V.fromList+#endif++instance {-# OVERLAPPABLE #-} (IsList (v a), Item (v a) ~ a, Monoid (v a), Eq (v a), V.Vector v a) => ListLike (v a) a where empty = V.empty singleton = V.singleton cons = V.cons@@ -72,8 +81,8 @@ filter = V.filter index = (!) findIndex = V.findIndex- toList = V.toList- fromList = V.fromList+ --toList = V.toList+ --fromList = V.fromList --fromListLike = fromList . toList --groupBy f = genericLength = fromInteger . fromIntegral . V.length@@ -85,9 +94,11 @@ sequence = liftM fromList . P.sequence . toList mapM func = liftM fromList . P.mapM func . toList +instance (Eq (v Char), V.Vector v Char) => IsString (v Char) where+ fromString = V.fromList+ instance (Eq (v Char), V.Vector v Char) => StringLike (v Char) where toString = V.toList- fromString = V.fromList --words = --lines = unwords = let sp = V.singleton ' ' in V.concat . intersperse sp . toList
src/Data/ListLike/Vector/Storable.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE MultiParamTypeClasses+ ,TypeFamilies ,FlexibleInstances #-} {-# OPTIONS -fno-warn-orphans #-} @@ -13,9 +14,11 @@ import Data.ListLike.Base import Data.ListLike.FoldableLL import Data.ListLike.String+import Data.String (IsString(fromString)) import Data.Monoid import Foreign.Storable (Storable)+import GHC.Exts (IsList(..)) instance Storable a => FoldableLL (V.Vector a) a where@@ -65,8 +68,8 @@ filter = V.filter index = (!) findIndex = V.findIndex- toList = V.toList- fromList = V.fromList+ --toList = V.toList+ --fromList = V.fromList --fromListLike = fromList . toList --groupBy f = genericLength = fromInteger . fromIntegral . V.length@@ -78,9 +81,11 @@ sequence = liftM fromList . P.sequence . toList mapM func = liftM fromList . P.mapM func . toList +instance IsString (V.Vector Char) where+ fromString = fromList+ instance StringLike (V.Vector Char) where toString = toList- fromString = fromList --words = --lines = unwords = let sp = V.singleton ' ' in V.concat . intersperse sp . toList
src/Data/ListLike/Vector/Unboxed.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE MultiParamTypeClasses+ ,TypeFamilies ,FlexibleInstances #-} {-# OPTIONS -fno-warn-orphans #-} @@ -13,8 +14,10 @@ import Data.ListLike.Base import Data.ListLike.FoldableLL import Data.ListLike.String+import Data.String (IsString(fromString)) import Data.Monoid+import GHC.Exts (IsList(..)) instance Unbox a => FoldableLL (V.Vector a) a where@@ -64,8 +67,8 @@ filter = V.filter index = (!) findIndex = V.findIndex- toList = V.toList- fromList = V.fromList+ --toList = V.toList+ --fromList = V.fromList --fromListLike = fromList . toList --groupBy f = genericLength = fromInteger . fromIntegral . V.length@@ -77,9 +80,11 @@ sequence = liftM fromList . P.sequence . toList mapM func = liftM fromList . P.mapM func . toList +instance IsString (V.Vector Char) where+ fromString = fromList+ instance StringLike (V.Vector Char) where toString = toList- fromString = fromList --words = --lines = unwords = let sp = V.singleton ' ' in V.concat . intersperse sp . toList
src/Data/ListLike/Vector/Vector.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE MultiParamTypeClasses+ ,TypeFamilies ,FlexibleInstances #-} {-# OPTIONS -fno-warn-orphans #-} @@ -13,8 +14,10 @@ import Data.ListLike.Base import Data.ListLike.FoldableLL import Data.ListLike.String+import Data.String (IsString(fromString)) import Data.Monoid+import GHC.Exts (IsList(..)) instance FoldableLL (V.Vector a) a where foldl = V.foldl@@ -63,8 +66,8 @@ filter = V.filter index = (!) findIndex = V.findIndex- toList = V.toList- fromList = V.fromList+ --toList = V.toList+ --fromList = V.fromList --fromListLike = fromList . toList --groupBy f = genericLength = fromInteger . fromIntegral . V.length@@ -76,9 +79,11 @@ sequence = liftM fromList . P.sequence . toList mapM func = liftM fromList . P.mapM func . toList +instance IsString (V.Vector Char) where+ fromString = fromList+ instance StringLike (V.Vector Char) where toString = toList- fromString = fromList --words = --lines = unwords = let sp = V.singleton ' ' in V.concat . intersperse sp . toList
testsrc/TestInfrastructure.hs view
@@ -6,6 +6,7 @@ ,FunctionalDependencies ,FlexibleInstances ,UndecidableInstances+ ,TypeFamilies ,FlexibleContexts #-} {-# OPTIONS -fno-warn-orphans #-} @@ -45,9 +46,11 @@ import qualified Test.HUnit as HU import Text.Printf import Data.Function (on)+import Data.String (IsString(fromString)) import Data.Word import Data.List import Data.Monoid (Monoid(..))+import GHC.Exts (IsList(Item)) simpleArb :: (LL.ListLike f i, Arbitrary i) => Gen f simpleArb = sized (\n -> choose (0, n) >>= myVector)@@ -273,15 +276,22 @@ mempty = MyList [] mappend (MyList x) (MyList y) = MyList (x ++ y) +instance IsList (MyList a) where+ type Item (MyList a) = a+ toList (MyList xs) = xs+ fromList = MyList+ instance LL.ListLike (MyList a) a where singleton x = MyList [x] head (MyList x) = head x tail (MyList x) = MyList (tail x) null (MyList x) = null x +instance IsString (MyList Char) where+ fromString = MyList+ instance LL.StringLike (MyList Char) where toString (MyList x) = x- fromString x = MyList x mkTest :: Testable prop => String -> prop -> HU.Test mkTest msg test = HU.TestLabel msg $ HU.TestCase (quickCheckResult test >>= HU.assertBool msg . isSuccess)@@ -390,7 +400,7 @@ w "Text.Lazy" (x::LLTest TL.Text Char), w "Text.Builder" (x::LLTest TB.Builder Char), w "UTF8 ByteString" (x::LLTest (UTF8.UTF8 BS.ByteString) Char),- w "UTF8 ByteString.Lazy" (x::LLTest (UTF8.UTF8 BSL.ByteString) Char)- ,w "Vector Char" (x::LLTest (V.Vector Char) Char),+ w "UTF8 ByteString.Lazy" (x::LLTest (UTF8.UTF8 BSL.ByteString) Char),+ w "Vector Char" (x::LLTest (V.Vector Char) Char), w "Vector.Unbox Char" (x::LLTest (VU.Vector Char) Char) ]
testsrc/runtests.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE CPP+ ,TypeFamilies ,ScopedTypeVariables ,RankNTypes ,ExistentialQuantification