Skip to content

Commit f2c343b

Browse files
authored
Merge pull request #136 from josephcsible/fail
Add a proper implementation of fail to the Alex monad
2 parents 2cd298f + 1dba941 commit f2c343b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

templates/wrappers.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
#if defined(ALEX_MONAD) || defined(ALEX_MONAD_BYTESTRING)
88
import Control.Applicative as App (Applicative (..))
9+
#if __GLASGOW_HASKELL__ >= 800
10+
import qualified Control.Monad.Fail as Fail
11+
#endif
912
#endif
1013

1114
import Data.Word (Word8)
@@ -225,6 +228,14 @@ instance Monad Alex where
225228
Left msg -> Left msg
226229
Right (s',a) -> unAlex (k a) s'
227230
return = App.pure
231+
#if __GLASGOW_HASKELL__ < 800
232+
fail = alexError
233+
#else
234+
fail = Fail.fail
235+
236+
instance Fail.MonadFail Alex where
237+
fail = alexError
238+
#endif
228239

229240
alexGetInput :: Alex AlexInput
230241
alexGetInput

0 commit comments

Comments
 (0)