summaryrefslogtreecommitdiff
path: root/src/Data/Bytes/Get.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Bytes/Get.hs')
-rw-r--r--src/Data/Bytes/Get.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/Data/Bytes/Get.hs b/src/Data/Bytes/Get.hs
index 3ad5e0a..656b071 100644
--- a/src/Data/Bytes/Get.hs
+++ b/src/Data/Bytes/Get.hs
@@ -27,6 +27,7 @@ module Data.Bytes.Get
import Control.Applicative
import Control.Monad.Reader
+import Control.Monad.Trans.Except as Except
import Control.Monad.RWS.Lazy as Lazy
import Control.Monad.RWS.Strict as Strict
import Control.Monad.State.Lazy as Lazy
@@ -407,6 +408,24 @@ instance (MonadGet m, Monoid w) => MonadGet (Lazy.RWST r w s m) where
factor = either id id
{-# INLINE lookAheadE #-}
+instance MonadGet m => MonadGet (ExceptT e m) where
+ type Remaining (ExceptT e m) = Remaining m
+ type Bytes (ExceptT e m) = Bytes m
+ lookAhead = mapExceptT lookAhead
+ {-# INLINE lookAhead #-}
+ lookAheadM (ExceptT m) = ExceptT (liftM factor $ lookAheadE $ liftM distribute m)
+ where
+ distribute (Left e) = (Left (Left e))
+ distribute (Right j) = (Right (Right j))
+ factor = either id id
+ {-# INLINE lookAheadM #-}
+ lookAheadE (ExceptT m) = ExceptT (liftM factor $ lookAheadE $ liftM distribute m)
+ where
+ distribute (Left e) = (Left (Left e))
+ distribute (Right a) = (Right (Right a))
+ factor = either id id
+ {-# INLINE lookAheadE #-}
+
-- | Get something from a lazy 'Lazy.ByteString' using 'B.runGet'.
runGetL :: B.Get a -> Lazy.ByteString -> a
runGetL = B.runGet