git.iko.soy/typeable/pandoc
on master help sign in
Docx Reader: Add a compatibility layer for Except.

mtl switched from ErrorT to ExceptT, but we're not sure which mtl we'll be dealing with. This should make errors work with both. The main difference (beside the name of the module and the monad transformer) is that Except doesn't require an instance of an Error Typeclass. So we define that for compatability. When we switch to a later mtl, using Control.Monad.Exception, we can just erase the instance declaration, and all should work fine.

commitfe2eda9d54e64ffa0c6c5c5295c19941040a5f3d authorJesse Rosenthal <jrosenthal@jhu.edu> dateSat 12 Jul 2014, 08:56 (12 years ago) parentd65fd58
3 files changed+31−3
pandoc.cabal+1 src/Text/Pandoc/Compat/Except.hs+27 src/Text/Pandoc/Readers/Docx/Parse.hs+3−3
pandoc.cabal+1
@@ -340,6 +340,7 @@ Library
340340 Text.Pandoc.Slides,
341341 Text.Pandoc.Highlighting,
342342 Text.Pandoc.Compat.Monoid,
343+ Text.Pandoc.Compat.Except,
343344 Text.Pandoc.Compat.TagSoupEntity,
344345 Paths_pandoc
345346
src/Text/Pandoc/Compat/Except.hsnew file+27
@@ -0,0 +1,27 @@
1+{-# LANGUAGE CPP #-}
2+module Text.Pandoc.Compat.Except ( ExceptT
3+ , Error(..)
4+ , runExceptT
5+ , throwError
6+ , catchError )
7+ where
8+
9+#if MIN_VERSION_mtl(2,2,1)
10+import Control.Monad.Except
11+
12+class Error a where
13+ noMsg :: a
14+ strMsg :: String -> a
15+
16+ noMsg = strMsg ""
17+ strMsg _ = noMsg
18+
19+#else
20+import Control.Monad.Error
21+type ExceptT = ErrorT
22+
23+runExceptT :: ExceptT e m a -> m (Either e a)
24+runExceptT = runErrorT
25+#endif
26+
27+
src/Text/Pandoc/Readers/Docx/Parse.hs+3−3
@@ -69,7 +69,7 @@ import qualified Data.ByteString.Lazy as B
6969import qualified Text.Pandoc.UTF8 as UTF8
7070import Control.Monad.Reader
7171import qualified Data.Map as M
72−import Control.Monad.Error
72+import Text.Pandoc.Compat.Except
7373
7474data ReaderEnv = ReaderEnv { envNotes :: Notes
7575 , envNumbering :: Numbering
@@ -84,10 +84,10 @@ data DocxError = DocxError | WrongElem
8484instance Error DocxError where
8585 noMsg = WrongElem
8686
87−type D = ErrorT DocxError (Reader ReaderEnv)
87+type D = ExceptT DocxError (Reader ReaderEnv)
8888
8989runD :: D a -> ReaderEnv -> Either DocxError a
90−runD dx re = runReader (runErrorT dx ) re
90+runD dx re = runReader (runExceptT dx ) re
9191
9292maybeToD :: Maybe a -> D a
9393maybeToD (Just a) = return a