Skip to content

Commit 1dba941

Browse files
committed
Add a proper implementation of fail to the Alex monad
1 parent c6c8870 commit 1dba941

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)
@@ -219,6 +222,14 @@ instance Monad Alex where
219222
Left msg -> Left msg
220223
Right (s',a) -> unAlex (k a) s'
221224
return = App.pure
225+
#if __GLASGOW_HASKELL__ < 800
226+
fail = alexError
227+
#else
228+
fail = Fail.fail
229+
230+
instance Fail.MonadFail Alex where
231+
fail = alexError
232+
#endif
222233

223234
alexGetInput :: Alex AlexInput
224235
alexGetInput

0 commit comments

Comments
 (0)