Skip to content

Commit e6387b2

Browse files
authored
Merge pull request #233 from HuwCampbell/topic/canonical_instances
Add MonadFail instances where appropriate
2 parents 7bd2530 + b400bf1 commit e6387b2

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

hedgehog/hedgehog.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ library
5959
, containers >= 0.4 && < 0.7
6060
, directory >= 1.2 && < 1.4
6161
, exceptions >= 0.7 && < 0.11
62+
, fail >= 4.9 && < 5
6263
, lifted-async >= 0.7 && < 0.11
6364
, mmorph >= 1.0 && < 1.2
6465
, monad-control >= 1.0 && < 1.1

hedgehog/src/Hedgehog/Internal/Gen.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ import Control.Monad (MonadPlus(..), filterM, replicateM, ap, join)
158158
import Control.Monad.Base (MonadBase(..))
159159
import Control.Monad.Catch (MonadThrow(..), MonadCatch(..))
160160
import Control.Monad.Error.Class (MonadError(..))
161+
import Control.Monad.Fail (MonadFail (..))
162+
import qualified Control.Monad.Fail as Fail
161163
import Control.Monad.IO.Class (MonadIO(..))
162164
import Control.Monad.Morph (MFunctor(..), MMonad(..), generalize)
163165
import Control.Monad.Primitive (PrimMonad(..))
@@ -553,6 +555,13 @@ instance Monad m => Monad (GenT m) where
553555
runGenT size sk . k =<<
554556
runGenT size sm m
555557

558+
fail =
559+
Fail.fail
560+
561+
instance Monad m => MonadFail (GenT m) where
562+
fail =
563+
error
564+
556565
instance Monad m => Alternative (GenT m) where
557566
empty =
558567
mzero

hedgehog/src/Hedgehog/Internal/Property.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ import Control.Monad.Base (MonadBase(..))
8484
import Control.Monad.Catch (MonadThrow(..), MonadCatch(..))
8585
import Control.Monad.Catch (SomeException(..), displayException)
8686
import Control.Monad.Error.Class (MonadError(..))
87+
import Control.Monad.Fail (MonadFail (..))
88+
import qualified Control.Monad.Fail as Fail
8789
import Control.Monad.IO.Class (MonadIO(..))
8890
import Control.Monad.Morph (MFunctor(..))
8991
import Control.Monad.Primitive (PrimMonad(..))
@@ -317,6 +319,10 @@ instance Monad m => Monad (TestT m) where
317319
unTest m >>=
318320
unTest . k
319321

322+
fail =
323+
Fail.fail
324+
325+
instance Monad m => MonadFail (TestT m) where
320326
fail err =
321327
TestT . ExceptT . pure . Left $ Failure Nothing err Nothing
322328

0 commit comments

Comments
 (0)