packages feed

string-class 0.1.5.1 → 0.1.6.1

raw patch · 2 files changed

+159/−22 lines, 2 filesdep ~bytestringdep ~taggeddep ~textPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: bytestring, tagged, text

API changes (from Hackage documentation)

+ Data.String.Class: altUnfoldrN64 :: StringCells s => Int64 -> (a -> Maybe (StringCellAltChar s, a)) -> a -> s
+ Data.String.Class: instance ConvLazyText ByteString
+ Data.String.Class: instance ConvLazyText GenString
+ Data.String.Class: instance ConvLazyText String
+ Data.String.Class: instance ConvLazyText Text
+ Data.String.Class: unfoldrN64 :: StringCells s => Int64 -> (a -> Maybe (StringCellChar s, a)) -> a -> s
- Data.String.Class: class (Eq s, Monoid s, IsString s, Typeable s, StringCell (StringCellChar s), StringCell (StringCellAltChar s), ConvGenString s, ConvString s, ConvStrictByteString s, ConvLazyByteString s, ConvText s) => StringCells s where { type family StringCellChar s; type family StringCellAltChar s; { unfoldr f b = case f b of { (Just (a, new_b)) -> a `cons` unfoldr f new_b (Nothing) -> empty } altUnfoldr f b = case f b of { (Just (a, new_b)) -> a `altCons` altUnfoldr f new_b (Nothing) -> empty } unfoldrN = const unfoldr altUnfoldrN = const altUnfoldr altCons c s = cons (s `untagTypeOf` toMainChar c) s altSnoc s c = snoc s (s `untagTypeOf` toMainChar c) altUncons s = (\ ~(a, s') -> (s `untagTypeOf` toAltChar a, s')) $ uncons s altUnsnoc s = (\ ~(s', a) -> (s', s `untagTypeOf` toAltChar a)) $ unsnoc s append = mappend concat = mconcat empty = mempty null = (== mempty) head = fst . uncons tail = snd . uncons last = snd . unsnoc init = fst . unsnoc altHead s = (s `untagTypeOf`) . toAltChar . head $ s altLast s = (s `untagTypeOf`) . toAltChar . last $ s index s 0 = head s index s n = (flip index $ pred n) . tail $ s index64 s 0 = head s index64 s n = (flip index64 $ pred n) . tail $ s genericIndex s 0 = head s genericIndex s n = (flip genericIndex $ pred n) . tail $ s take n s = take64 (fromIntegral n) s take64 n s = genericTake (fromIntegral n :: Integer) s genericTake n s = take (fromIntegral n) s drop n s = drop64 (fromIntegral n) s drop64 n s = genericDrop (fromIntegral n :: Integer) s genericDrop n s = drop (fromIntegral n) s length = fromIntegral . length64 length64 = (fromIntegral :: Integer -> Int64) . genericLength genericLength = fromIntegral . length uncons s = (head s, tail s) unsnoc s = (init s, last s) cons2 a b s = a `cons` b `cons` s cons3 a b c s = a `cons` b `cons` c `cons` s cons4 a b c d s = a `cons` b `cons` c `cons` d `cons` s uncons2 s = let (a, s') = uncons s (b, s'') = uncons s' in (a, b, s'') uncons3 s = let (a, s') = uncons s (b, s'') = uncons s' (c, s''') = uncons s'' in (a, b, c, s''') uncons4 s = let (a, s') = uncons s (b, s'') = uncons s' (c, s''') = uncons s'' (d, s'''') = uncons s''' in (a, b, c, d, s'''') safeUncons s | null s = Nothing | otherwise = Just $ uncons s safeUnsnoc s | null s = Nothing | otherwise = Just $ unsnoc s safeAltUncons s | null s = Nothing | otherwise = Just $ altUncons s safeAltUnsnoc s | null s = Nothing | otherwise = Just $ altUnsnoc s safeHead s | null s = Nothing | otherwise = Just $ head s safeTail s | null s = Nothing | otherwise = Just $ tail s safeLast s | null s = Nothing | otherwise = Just $ last s safeInit s | null s = Nothing | otherwise = Just $ init s safeAltHead s | null s = Nothing | otherwise = Just $ altHead s safeAltLast s | null s = Nothing | otherwise = Just $ altLast s safeIndex s n | length s <= n = Nothing | otherwise = Just $ s `index` n safeIndex64 s n | length64 s <= n = Nothing | otherwise = Just $ s `index64` n safeGenericIndex s n | genericLength s <= n = Nothing | otherwise = Just $ s `genericIndex` n safeTake n s | n > length s = Nothing | otherwise = Just $ take n s safeTake64 n s | n > length64 s = Nothing | otherwise = Just $ take64 n s safeGenericTake n s | n > genericLength s = Nothing | otherwise = Just $ genericTake n s safeDrop n s | n > length s = Nothing | otherwise = Just $ drop n s safeDrop64 n s | n > length64 s = Nothing | otherwise = Just $ drop64 n s safeGenericDrop n s | n > genericLength s = Nothing | otherwise = Just $ genericDrop n s safeUncons2 s = do { (a, s') <- safeUncons s; (b, s'') <- safeUncons s'; return (a, b, s'') } safeUncons3 s = do { (a, s') <- safeUncons s; (b, s'') <- safeUncons s'; (c, s''') <- safeUncons s''; return (a, b, c, s''') } safeUncons4 s = do { (a, s') <- safeUncons s; (b, s'') <- safeUncons s'; (c, s''') <- safeUncons s''; (d, s'''') <- safeUncons s'''; return (a, b, c, d, s'''') } } }
+ Data.String.Class: class (Eq s, Monoid s, IsString s, Typeable s, StringCell (StringCellChar s), StringCell (StringCellAltChar s), ConvGenString s, ConvString s, ConvStrictByteString s, ConvLazyByteString s, ConvText s, ConvLazyText s) => StringCells s where type family StringCellChar s type family StringCellAltChar s unfoldr f b = case f b of { (Just (a, new_b)) -> a `cons` unfoldr f new_b (Nothing) -> empty } altUnfoldr f b = case f b of { (Just (a, new_b)) -> a `altCons` altUnfoldr f new_b (Nothing) -> empty } unfoldrN = const unfoldr altUnfoldrN = const altUnfoldr unfoldrN64 l f z = unfoldrN (fromIntegral l) f z altUnfoldrN64 l f z = altUnfoldrN (fromIntegral l) f z altCons c s = cons (s `untagTypeOf` toMainChar c) s altSnoc s c = snoc s (s `untagTypeOf` toMainChar c) altUncons s = (\ ~(a, s') -> (s `untagTypeOf` toAltChar a, s')) $ uncons s altUnsnoc s = (\ ~(s', a) -> (s', s `untagTypeOf` toAltChar a)) $ unsnoc s append = mappend concat = mconcat empty = mempty null = (== mempty) head = fst . uncons tail = snd . uncons last = snd . unsnoc init = fst . unsnoc altHead s = (s `untagTypeOf`) . toAltChar . head $ s altLast s = (s `untagTypeOf`) . toAltChar . last $ s index s 0 = head s index s n = (flip index $ pred n) . tail $ s index64 s 0 = head s index64 s n = (flip index64 $ pred n) . tail $ s genericIndex s 0 = head s genericIndex s n = (flip genericIndex $ pred n) . tail $ s take n s = take64 (fromIntegral n) s take64 n s = genericTake (fromIntegral n :: Integer) s genericTake n s = take (fromIntegral n) s drop n s = drop64 (fromIntegral n) s drop64 n s = genericDrop (fromIntegral n :: Integer) s genericDrop n s = drop (fromIntegral n) s length = fromIntegral . length64 length64 = (fromIntegral :: Integer -> Int64) . genericLength genericLength = fromIntegral . length uncons s = (head s, tail s) unsnoc s = (init s, last s) cons2 a b s = a `cons` b `cons` s cons3 a b c s = a `cons` b `cons` c `cons` s cons4 a b c d s = a `cons` b `cons` c `cons` d `cons` s uncons2 s = let (a, s') = uncons s (b, s'') = uncons s' in (a, b, s'') uncons3 s = let (a, s') = uncons s (b, s'') = uncons s' (c, s''') = uncons s'' in (a, b, c, s''') uncons4 s = let (a, s') = uncons s (b, s'') = uncons s' (c, s''') = uncons s'' (d, s'''') = uncons s''' in (a, b, c, d, s'''') safeUncons s | null s = Nothing | otherwise = Just $ uncons s safeUnsnoc s | null s = Nothing | otherwise = Just $ unsnoc s safeAltUncons s | null s = Nothing | otherwise = Just $ altUncons s safeAltUnsnoc s | null s = Nothing | otherwise = Just $ altUnsnoc s safeHead s | null s = Nothing | otherwise = Just $ head s safeTail s | null s = Nothing | otherwise = Just $ tail s safeLast s | null s = Nothing | otherwise = Just $ last s safeInit s | null s = Nothing | otherwise = Just $ init s safeAltHead s | null s = Nothing | otherwise = Just $ altHead s safeAltLast s | null s = Nothing | otherwise = Just $ altLast s safeIndex s n | length s <= n = Nothing | otherwise = Just $ s `index` n safeIndex64 s n | length64 s <= n = Nothing | otherwise = Just $ s `index64` n safeGenericIndex s n | genericLength s <= n = Nothing | otherwise = Just $ s `genericIndex` n safeTake n s | n > length s = Nothing | otherwise = Just $ take n s safeTake64 n s | n > length64 s = Nothing | otherwise = Just $ take64 n s safeGenericTake n s | n > genericLength s = Nothing | otherwise = Just $ genericTake n s safeDrop n s | n > length s = Nothing | otherwise = Just $ drop n s safeDrop64 n s | n > length64 s = Nothing | otherwise = Just $ drop64 n s safeGenericDrop n s | n > genericLength s = Nothing | otherwise = Just $ genericDrop n s safeUncons2 s = do { (a, s') <- safeUncons s; (b, s'') <- safeUncons s'; return (a, b, s'') } safeUncons3 s = do { (a, s') <- safeUncons s; (b, s'') <- safeUncons s'; (c, s''') <- safeUncons s''; return (a, b, c, s''') } safeUncons4 s = do { (a, s') <- safeUncons s; (b, s'') <- safeUncons s'; (c, s''') <- safeUncons s''; (d, s'''') <- safeUncons s'''; return (a, b, c, d, s'''') }
- Data.String.Class: class StringRWIO s
+ Data.String.Class: class StringRWIO s where interact f = putStr . f =<< getContents getContents = hGetContents stdin getLine = hGetLine stdin putStr = hPutStr stdout putStrLn = hPutStrLn stdout readFile fn = hGetContents =<< openFile fn ReadMode writeFile fn s = withFile fn WriteMode $ \ hdl -> hPutStr hdl s appendFile fn s = withFile fn AppendMode $ \ hdl -> hPutStr hdl s

Files

src/Data/String/Class.hs view
@@ -31,6 +31,9 @@ import qualified Data.Text.Encoding as TE import qualified Data.Text.Encoding.Error as TEE import qualified Data.Text.IO as T+import qualified Data.Text.Lazy as LT+import qualified Data.Text.Lazy.Encoding as LTE+import qualified Data.Text.Lazy.IO as LT import Data.Typeable import Data.Word import qualified System.IO as IO@@ -40,7 +43,7 @@ instance (StringCells s, StringRWIO s) => Stringy s  -- | Minimal complete definition: StringCellChar; StringCellAltChar; toStringCells; fromStringCells; toMainChar; toAltChar; cons; snoc; either all of head, tail, last, and init, or all of uncons and unsnoc; take, take64 or genericTake; drop, drop64, or genericDrop; and length, length64, or genericLength-class (Eq s, Monoid s, IsString s, Typeable s, StringCell (StringCellChar s), StringCell (StringCellAltChar s), ConvGenString s, ConvString s, ConvStrictByteString s, ConvLazyByteString s, ConvText s) => StringCells s where+class (Eq s, Monoid s, IsString s, Typeable s, StringCell (StringCellChar s), StringCell (StringCellAltChar s), ConvGenString s, ConvString s, ConvStrictByteString s, ConvLazyByteString s, ConvText s, ConvLazyText s) => StringCells s where     type StringCellChar s     type StringCellAltChar s @@ -80,12 +83,14 @@      -- | Construction of a string; implementations should behave safely with incorrect lengths     ---    -- The default implementation of 'undfoldr' is independent from that of 'altUnfoldr',+    -- The default implementation of 'unfoldr' is independent from that of 'altUnfoldr',     -- as well as 'unfoldrN' as and 'altUnfoldrN'.-    unfoldr     ::        (a -> Maybe (StringCellChar    s, a)) -> a -> s-    altUnfoldr  ::        (a -> Maybe (StringCellAltChar s, a)) -> a -> s-    unfoldrN    :: Int -> (a -> Maybe (StringCellChar    s, a)) -> a -> s-    altUnfoldrN :: Int -> (a -> Maybe (StringCellAltChar s, a)) -> a -> s+    unfoldr       ::          (a -> Maybe (StringCellChar    s, a)) -> a -> s+    altUnfoldr    ::          (a -> Maybe (StringCellAltChar s, a)) -> a -> s+    unfoldrN      :: Int   -> (a -> Maybe (StringCellChar    s, a)) -> a -> s+    altUnfoldrN   :: Int   -> (a -> Maybe (StringCellAltChar s, a)) -> a -> s+    unfoldrN64    :: Int64 -> (a -> Maybe (StringCellChar    s, a)) -> a -> s+    altUnfoldrN64 :: Int64 -> (a -> Maybe (StringCellAltChar s, a)) -> a -> s      unfoldr f b =         case f b of@@ -99,6 +104,10 @@     unfoldrN    = const unfoldr     altUnfoldrN = const altUnfoldr +    unfoldrN64 l f z = unfoldrN (fromIntegral l) f z++    altUnfoldrN64 l f z = altUnfoldrN (fromIntegral l) f z+     -- | Get the character at the given position     --     -- Just like 'drop', 'drop64', and the variants of those functions, the@@ -333,6 +342,10 @@     toText :: s -> T.Text     fromText :: T.Text -> s +class ConvLazyText s where+    toLazyText :: s -> LT.Text+    fromLazyText :: LT.Text -> s+ -- | Minimal complete definition: 'hGetContents', 'hGetLine', 'hPutStr', and 'hPutStrLn' class StringRWIO s where     --- Handles@@ -531,6 +544,36 @@     append          = T.append     concat          = T.concat +instance StringCells LT.Text where+    type StringCellChar    LT.Text = Char+    type StringCellAltChar LT.Text = Char++    toStringCells   = fromLazyText+    fromStringCells = toLazyText++    length64        = LT.length+    empty           = LT.empty+    null            = LT.null+    cons            = LT.cons+    safeUncons      = LT.uncons+    uncons          = maybe (error "StringCells.Data.Text.Lazy.Text.uncons: string is null") id . safeUncons+    snoc            = LT.snoc+    altSnoc         = LT.snoc+    toMainChar      = Tagged . toChar+    toAltChar       = Tagged . toChar+    head            = LT.head+    tail            = LT.tail+    init            = LT.init+    last            = LT.last+    unfoldr         = LT.unfoldr+    altUnfoldr      = LT.unfoldr+    unfoldrN64      = LT.unfoldrN+    altUnfoldrN64   = LT.unfoldrN+    index s         = index64 s . fromIntegral+    index64         = LT.index+    append          = LT.append+    concat          = LT.concat+ instance StringCell Char where     toChar     = id     toWord8    = BI.c2w@@ -615,6 +658,11 @@     fromGenString _s = case _s of         (GenString _s) -> toStringCells _s +instance ConvGenString LT.Text where+    toGenString      = GenString+    fromGenString _s = case _s of+        (GenString _s) -> toStringCells _s+ instance ConvString GenString where     toString   = fromGenString     fromString = toGenString@@ -635,6 +683,10 @@     toString   = T.unpack     fromString = T.pack +instance ConvString LT.Text where+    toString   = LT.unpack+    fromString = LT.pack+ instance ConvStrictByteString GenString where     toStrictByteString   = fromGenString     fromStrictByteString = toGenString@@ -648,13 +700,17 @@     fromStrictByteString = id  instance ConvStrictByteString L.ByteString where-    toStrictByteString   = S.concat . L.toChunks+    toStrictByteString   = L.toStrict     fromStrictByteString = toLazyByteString  instance ConvStrictByteString T.Text where     toStrictByteString   = TE.encodeUtf8     fromStrictByteString = toText +instance ConvStrictByteString LT.Text where+    toStrictByteString   = toStrictByteString . LTE.encodeUtf8+    fromStrictByteString = toLazyText+ instance ConvLazyByteString GenString where     toLazyByteString   = fromGenString     fromLazyByteString = toGenString@@ -664,7 +720,7 @@     fromLazyByteString = LC.unpack  instance ConvLazyByteString S.ByteString where-    toLazyByteString   = L.fromChunks . (:[])+    toLazyByteString   = L.fromStrict     fromLazyByteString = toStrictByteString  instance ConvLazyByteString L.ByteString where@@ -675,6 +731,10 @@     toLazyByteString   = toLazyByteString . toStrictByteString     fromLazyByteString = toText +instance ConvLazyByteString LT.Text where+    toLazyByteString   = toLazyByteString . toStrictByteString+    fromLazyByteString = toLazyText+ instance ConvText GenString where     toText   = fromGenString     fromText = toGenString@@ -695,6 +755,34 @@     toText   = id     fromText = id +instance ConvText LT.Text where+    toText   = LT.toStrict+    fromText = toLazyText++instance ConvLazyText GenString where+    toLazyText   = fromGenString+    fromLazyText = toGenString++instance ConvLazyText String where+    toLazyText   = LT.pack+    fromLazyText = LT.unpack++instance ConvLazyText S.ByteString where+    toLazyText   = LTE.decodeUtf8With TEE.lenientDecode . toLazyByteString+    fromLazyText = toStrictByteString++instance ConvLazyText L.ByteString where+    toLazyText   = LTE.decodeUtf8With TEE.lenientDecode+    fromLazyText = toLazyByteString++instance ConvLazyText T.Text where+    toLazyText   = LT.fromStrict+    fromLazyText = fromLazyText++instance ConvLazyText LT.Text where+    toLazyText   = id+    fromLazyText = id+ -- | -- -- This is minimally defined with 'GenStringDefault'.@@ -753,7 +841,7 @@      hPutStr      = S.hPutStr -    hPutStrLn    = S.hPutStrLn+    hPutStrLn    = SC.hPutStrLn      interact     = S.interact @@ -763,7 +851,7 @@      putStr       = S.putStr -    putStrLn     = S.putStrLn+    putStrLn     = SC.putStrLn      readFile     = S.readFile @@ -794,7 +882,7 @@      putStr       = L.putStr -    putStrLn     = L.putStrLn+    putStrLn     = LC.putStrLn      readFile     = L.readFile @@ -829,6 +917,34 @@     writeFile    = T.writeFile      appendFile   = T.appendFile++-- |+--+-- See 'Data.Text.Lazy.IO' for documentation of behaviour.+instance StringRWIO LT.Text where+    hGetContents = LT.hGetContents++    hGetLine     = LT.hGetLine++    hPutStr      = LT.hPutStr++    hPutStrLn    = LT.hPutStrLn++    interact     = LT.interact++    getContents  = LT.getContents++    getLine      = LT.getLine++    putStr       = LT.putStr++    putStrLn     = LT.putStrLn++    readFile     = LT.readFile++    writeFile    = LT.writeFile++    appendFile   = LT.appendFile  -- | Polymorphic container of a string --
string-class.cabal view
@@ -1,25 +1,46 @@ name:                  string-class-version:               0.1.5.1+version:               0.1.6.1 cabal-version:         >= 1.10 build-type:            Simple license:               BSD3 license-file:          LICENSE copyright:             Copyright (C) 2010 Byron James Johnson author:                Byron James Johnson-maintainer:            KrabbyKrap@gmail.com+maintainer:            ByronJohnsonFP@gmail.com synopsis:              String class library description:           String class library category:              Data, Text-tested-with:           GHC == 7.0.2+tested-with:           GHC == 7.8.2  library-    default-language:  Haskell2010-    hs-source-dirs:    src-    build-depends:     base >= 4 && < 5, bytestring, text, tagged-    exposed-modules:   Data.String.Class-    ghc-options:       -Wall-    other-extensions:  TypeFamilies, FlexibleContexts, TypeSynonymInstances, ExistentialQuantification, DeriveDataTypeable, FlexibleInstances, UndecidableInstances+  default-language: Haskell2010+  hs-source-dirs:   src+  ghc-options:      -Wall+  default-extensions:+    --,GADTs+    --,TemplateHaskell+    DeriveDataTypeable+  other-extensions:+    TypeFamilies+   ,FlexibleContexts+   ,TypeSynonymInstances+   ,ExistentialQuantification+   ,DeriveDataTypeable+   ,FlexibleInstances+   ,UndecidableInstances+  -- Haven't thoroughly checked version bounds.+  -- I added as the minimum version for each non-base package the most recent+  -- version as of this repository's initial commit.+  build-depends:+    base       >= 4        && < 5+   -- bytestring's toStrict and fromString methods were first introduced in 0.10.0.0.+   --,bytestring >= 0.9.1.8  && < 0.11+   ,bytestring >= 0.10.0.0 && < 0.11+   ,text       >= 0.11.0.1 && < 1.3+   ,tagged     >= 0.1.1    && < 0.8+  exposed-modules:+    Data.String.Class  source-repository head-    type:              darcs-    location:          http://patch-tag.com/r/bob/string-class+  type:     git+  location: git@github.com:bairyn/string-class.git