Make package work with base-4.3 and mtl-2

Ignore-this: 85b05556d0b7b5968d2d0340ea9daf5d

darcs-hash:20110425123827-a4fee-dd4f4c2a305d9937316b57dbe50ce154494032ac
This commit is contained in:
Henning Guenther 2011-04-25 05:38:27 -07:00
parent ce0aa549b7
commit 44f3f083aa
4 changed files with 33 additions and 32 deletions

View File

@ -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))

View File

@ -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
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)-}

5
NEWS
View File

@ -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
---------------------------

View File

@ -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