Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

20 lines (15 sloc) 619 Bytes
module Util where
import Control.Error (readMay, tryIO, eitherT)
import Data.Binary (Binary, decodeOrFail)
import qualified Data.ByteString.Lazy as LZ
tryIO' :: (IOError -> e) -> IO (Either e b) -> IO (Either e b)
tryIO' mapErr io = eitherT (return . Left . mapErr) return (tryIO io)
decodeM :: (Binary a, Monad m) => LZ.ByteString -> m a
decodeM bytes = case decodeOrFail bytes of
Left (_,_,e) -> fail e
Right (_,_,x) -> return x
-- | Signal read errors in some Monad (for parsing)
readM :: (Read r, Monad m) => String -> m r
readM s = case readMay s of
Just x -> return x
Nothing -> fail $ s ++ " is invalid"
Jump to Line
Something went wrong with that request. Please try again.