Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Data/Binary/Get.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ module Data.Binary.Get (
, lookAheadM
, lookAheadE
, label
, failGet

-- ** ByteStrings
, getByteString
Expand Down
15 changes: 11 additions & 4 deletions src/Data/Binary/Get/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module Data.Binary.Get.Internal (
, readN
, readNWith

, failGet

-- * Parsing
, bytesRead
, isolate
Expand Down Expand Up @@ -92,7 +94,7 @@ instance Monad Get where
return = pure
(>>=) = bindG
#if !(MIN_VERSION_base(4,9,0))
fail = failG -- base < 4.9
fail = failGet -- base < 4.9
#elif !(MIN_VERSION_base(4,13,0))
fail = Fail.fail -- base < 4.13
#endif
Expand All @@ -103,15 +105,20 @@ instance Monad Get where

#if MIN_VERSION_base(4,9,0)
instance Fail.MonadFail Get where
fail = failG
fail = failGet
#endif

bindG :: Get a -> (a -> Get b) -> Get b
bindG (C c) f = C $ \i ks -> c i (\i' a -> (runCont (f a)) i' ks)
{-# INLINE bindG #-}

failG :: String -> Get a
failG str = C $ \i _ks -> Fail i str
-- | Let the 'Get' action fail with an error message.
--
-- > failGet = fail @Get
--
-- @since x.x.x.x
failGet :: String -> Get a
failGet str = C $ \i _ks -> Fail i str

apG :: Get (a -> b) -> Get a -> Get b
apG d e = do
Expand Down
Loading