From 03fbbc3a9652372f64989c7cd3ab7583049f6a73 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Fri, 7 Feb 2020 13:08:10 +0100 Subject: [PATCH] Why did I implement this overly complicated lift by hand again ? --- src/PDF/Pages.hs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/PDF/Pages.hs b/src/PDF/Pages.hs index 31cdb6d..e7c61d6 100755 --- a/src/PDF/Pages.hs +++ b/src/PDF/Pages.hs @@ -8,7 +8,7 @@ module PDF.Pages ( import Codec.Compression.Zlib (decompress) import Control.Applicative ((<|>)) import Control.Monad (foldM) -import Control.Monad.RWS (RWST(..), ask, evalRWST, mapRWST, modify) +import Control.Monad.RWS (RWST(..), ask, evalRWST, lift, modify) import qualified Control.Monad.RWS as RWS (get) import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as Lazy (fromStrict, toStrict) @@ -35,15 +35,11 @@ data Page = Page { infixl 1 \\= (\\=) :: T a -> (a -> Either String b) -> T b -x \\= f = mapRWST ((\(a, s, w) -> (\b -> (b, s, w)) <$> f a) =<<) x +x \\= f = x >>= lift . f infixl 1 //= (//=) :: Either String a -> (a -> T b) -> T b -(//=) (Left e) _ = RWST (\_ _ -> Left e) -(//=) (Right a) f = f a - -lift :: Either String a -> T a -lift x = x //= return +x //= f = lift x >>= f expected :: Show a => String -> a -> Either String b expected name = Left . printf "Not a %s: %s" name . show