haskell-hedgehog
                                
                                
                                
                                    haskell-hedgehog copied to clipboard
                            
                            
                            
                        Add `MonadFail` instance to `Gen` data type
Without this instance it's impossible to perform partial pattern-matching inside property-based tests. Maybe this instance can be somehow smart, like, discard all cases that doesn't match the case?
If you switch to GHC 8.6 you'll also get a compiler error because of the MonadFail proposal, as discussed in https://github.com/hedgehogqa/haskell-hedgehog/pull/233. In fact, @HuwCampbell proposed
instance Monad m => MonadFail (GenT m) where
  fail _ =
    mzero
which actually discards ━ a change we don't consider making at the moment, as it requires a major version bump. So, for this reason (still in #233) we lean towards
instance Monad m => MonadFail (GenT m) where
  fail =
    error
which at least won't break your code when switching to GHC 8.6. ━ It'd be nice to have your thoughts around this.
@moodmosaic I'm actually okay with having error for now, works for me as well :+1:
I think discarding is the correct thing to do, personally. One could imagine doing something like
Just foo <- forAll ...
And having tests run, rather than the test crash.
Yes, discarding looks good, but also requires a major version bump, because it's a breaking change. In reality though, it's more or less what @sol tries to explain here:
MonadFail is still fairly new and we as a community don't have the collective experience yet on how things will pan out in practice.
That you get compile-time errors instead of runtime errors in some situations now is an intentional change. It's the whole point of introducing MonadFail.
I'm really curious to see what happens with https://github.com/nick8325/quickcheck/pull/228.
Any more thoughts here? Or should we just consider it incorrect to pattern match in this way in tests?
Follow https://github.com/hedgehogqa/haskell-hedgehog/pull/257 for updates.
Thanks!