We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4388c62 commit d05340eCopy full SHA for d05340e
MonadTransformers/4.5/MonadReadError.hs
@@ -0,0 +1,14 @@
1
+{-# LANGUAGE FlexibleContexts #-}
2
+module MonadReadError where
3
+
4
+import Control.Monad.Except
5
6
7
+data ReadError = EmptyInput | NoParse String deriving Show
8
9
+tryRead :: (Read a, MonadError ReadError m) => String -> m a
10
+tryRead [] = throwError EmptyInput
11
+tryRead s = f $ reads s where
12
+ f [(n, "")] = return n
13
+ f [(n, xs)] = throwError $ NoParse s
14
+ f [] = throwError $ NoParse s
0 commit comments