... | ... | @@ -199,25 +199,22 @@ Both of those tell us the "real" desugaring as just another pattern we could rec |
|
|
|
|
|
- Help! My code is broken because of a missing `MonadFail` instance! *Here are your options:*
|
|
|
|
|
|
1. Write a `MonadFail` instance (and bring it into scope)
|
|
|
1. Write a `MonadFail` instance (and bring it into scope). The [ fail](http://hackage.haskell.org/package/fail) provides a forward-compatible `MonadFail` class for GHC versions prior to GHC 8.0
|
|
|
|
|
|
```
|
|
|
#if !MIN_VERSION_base(4,11,0)
|
|
|
-- Control.Monad.Fail import will become redundant in GHC 7.16+
|
|
|
import qualified Control.Monad.Fail as Fail
|
|
|
#endif
|
|
|
import Control.Monad
|
|
|
-- Control.Monad.Fail import will become redundant in GHC 8.8+
|
|
|
import qualified Control.Monad.Fail as Fail
|
|
|
|
|
|
instance Monad Foo where
|
|
|
(>>=) = <...bind impl...>
|
|
|
-- NB: `return` defaults to `pure`
|
|
|
#if !MIN_VERSION_base(4,11,0)
|
|
|
-- Monad(fail) will be removed in GHC 7.16+
|
|
|
fail = Fail.fail
|
|
|
#endif
|
|
|
(>>=) = <...bind impl...>
|
|
|
-- NB: `return` defaults to `pure` since GHC 7.10
|
|
|
|
|
|
-- Monad(fail) will be removed in GHC 8.8+
|
|
|
fail = Fail.fail
|
|
|
|
|
|
instance MonadFail Foo where
|
|
|
fail = <...fail implementation...>
|
|
|
fail = <...fail implementation...>
|
|
|
```
|
|
|
1. Change your pattern to be irrefutable
|
|
|
1. Emulate the old behaviour by desugaring the pattern match by hand:
|
... | ... | @@ -225,7 +222,11 @@ Both of those tell us the "real" desugaring as just another pattern we could rec |
|
|
```
|
|
|
do Left e <- foobar
|
|
|
stuff
|
|
|
}}} becomes {{{#!haskell
|
|
|
```
|
|
|
|
|
|
becomes
|
|
|
|
|
|
```
|
|
|
do x <- foobar
|
|
|
e <- case x of
|
|
|
Left e' -> e'
|
... | ... | @@ -277,6 +278,9 @@ The roadmap is similar to the [ AMP](https://github.com/quchen/articles/blob/mas |
|
|
- Add a language extension `-XMonadFailDesugaring` that changes desugaring to use `MonadFail(fail)` instead of `Monad(fail)` This has the effect that typechecking will infer a `MonadFail` constraint for `do` blocks with failable patterns, just as it is planned to do when the entire thing is done.
|
|
|
- Add a warning when a `do` block that contains a failable pattern is desugared, but there is no `MonadFail` instance in scope: "Please add the instance or change your pattern matching." Add a flag to control whether this warning appears, but leave it off by default.
|
|
|
- Add a warning when an instance implements the `fail` function (or when `fail` is imported as a method of `Monad` , as it will be removed from the `Monad` class in the future. (See also [ GHC \#10071](https://ghc.haskell.org/trac/ghc/ticket/10071)). Leave it off by default.
|
|
|
- GHC 8.2
|
|
|
|
|
|
- *(nothing happens)*
|
|
|
- GHC 8.4
|
|
|
|
|
|
- Turn on the warning about missing `MonadFail` instances that we added in 8.0 by default.
|
... | ... | |