diff --git a/Data/Encoding/ByteSink.hs b/Data/Encoding/ByteSink.hs index 09f76ae..3985e9c 100644 --- a/Data/Encoding/ByteSink.hs +++ b/Data/Encoding/ByteSink.hs @@ -101,20 +101,15 @@ instance ByteSink PutME where pushWord64be w = PutME $ Right (putWord64be w,()) pushWord64le w = PutME $ Right (putWord64le w,()) -#ifndef MIN_VERSION_mtl(2,0,0,0) +#if MIN_VERSION_base(4,3,0) +#else instance Monad (Either EncodingException) where return x = Right x Left err >>= g = Left err Right x >>= g = g x #endif -instance Throws EncodingException (State (Seq Char)) where - throwException = throw - -instance ByteSink (State (Seq Char)) where - pushWord8 x = modify (|> (chr $ fromIntegral x)) - -instance ByteSink (StateT (Seq Char) (Either EncodingException)) where +instance (Monad m,Throws EncodingException m) => ByteSink (StateT (Seq Char) m) where pushWord8 x = modify (|> (chr $ fromIntegral x)) newtype StrictSink a = StrictS (Ptr Word8 -> Int -> Int -> IO (a,Ptr Word8,Int,Int)) diff --git a/Data/Encoding/ByteSource.hs b/Data/Encoding/ByteSource.hs index 09d1676..4c5550c 100644 --- a/Data/Encoding/ByteSource.hs +++ b/Data/Encoding/ByteSource.hs @@ -103,10 +103,7 @@ instance ByteSource Get where fetchWord64be = getWord64be fetchWord64le = getWord64le -instance Throws DecodingException (State [Char]) where - throwException = throw - -instance ByteSource (State [Char]) where +instance ByteSource (StateT [Char] Identity) where sourceEmpty = gets null fetchWord8 = do chs <- get @@ -121,7 +118,8 @@ instance ByteSource (State [Char]) where put chs return res -#ifndef MIN_VERSION_mtl(2,0,0,0) +#if MIN_VERSION_base(4,3,0) +#else instance Monad (Either DecodingException) where return = Right (Left err) >>= g = Left err @@ -143,31 +141,17 @@ instance ByteSource (StateT [Char] (Either DecodingException)) where put chs return res -instance Throws DecodingException (State BS.ByteString) where - throwException = throw - -instance ByteSource (State BS.ByteString) where +instance (Monad m,Throws DecodingException m) => ByteSource (StateT BS.ByteString m) where sourceEmpty = gets BS.null - fetchWord8 = State (\str -> case BS.uncons str of + fetchWord8 = StateT (\str -> case BS.uncons str of Nothing -> throw UnexpectedEnd - Just (c,cs) -> (c,cs)) + Just (c,cs) -> return (c,cs)) fetchAhead act = do str <- get res <- act put str return res -instance ByteSource (StateT BS.ByteString (Either DecodingException)) where - sourceEmpty = gets BS.null - fetchWord8 = StateT (\str -> case BS.uncons str of - Nothing -> Left UnexpectedEnd - Just ns -> Right ns) - fetchAhead act = do - chs <- get - res <- act - put chs - return res - instance ByteSource (StateT LBS.ByteString (Either DecodingException)) where sourceEmpty = gets LBS.null fetchWord8 = StateT (\str -> case LBS.uncons str of @@ -193,4 +177,21 @@ instance ByteSource (ReaderT Handle IO) where pos <- liftIO $ hGetPosn h res <- act liftIO $ hSetPosn pos - return res \ No newline at end of file + return res + sourcePos = do + h <- ask + p <- liftIO $ hTell h + return $ Just p + +{- +instance Throws DecodingException (State st) => Throws DecodingException (State (Integer,st)) where + throwException = throw + +instance ByteSource (State st) => ByteSource (State (Integer,st)) where + sourceEmpty = sourceEmpty + fetchWord8 = do + <- fetchWord8 + fetchAhead = fetchAhead + sourcePos = do + (p,chs) <- get + return (Just p)-} \ No newline at end of file diff --git a/NEWS b/NEWS index 584e2c4..8d50f77 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +Changes from 0.6.4 to 0.6.5 +--------------------------- + +* Make package work with >=base-4.3.0.0 and mtl-2 + Changes from 0.6.3 to 0.6.4 --------------------------- diff --git a/encoding.cabal b/encoding.cabal index a461d91..845f087 100644 --- a/encoding.cabal +++ b/encoding.cabal @@ -1,5 +1,5 @@ Name: encoding -Version: 0.6.4 +Version: 0.6.5 Author: Henning Günther Maintainer: h.guenther@tu-bs.de License: BSD3