... | ... | @@ -168,17 +168,16 @@ 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+importqualifiedControl.Monad.Failas Fail
|
|
|
#endif
|
|
|
importControl.MonadinstanceMonadFoowhere(>>=)=<...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
|
|
|
importControl.Monad-- Control.Monad.Fail import will become redundant in GHC 8.8+importqualifiedControl.Monad.Failas Fail
|
|
|
|
|
|
instanceMonadFoowhere(>>=)=<...bind impl...>-- NB: `return` defaults to `pure` since GHC 7.10-- Monad(fail) will be removed in GHC 8.8+
|
|
|
fail =Fail.fail
|
|
|
|
|
|
instanceMonadFailFoowhere
|
|
|
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:
|
... | ... | @@ -186,7 +185,11 @@ Both of those tell us the "real" desugaring as just another pattern we could rec |
|
|
```
|
|
|
doLeft e <- foobar
|
|
|
stuff
|
|
|
}}} becomes {{{#!haskell
|
|
|
```
|
|
|
|
|
|
becomes
|
|
|
|
|
|
```
|
|
|
do x <- foobar
|
|
|
e <-case x ofLeft e' -> e'
|
|
|
Right r ->error"Pattern match failed"-- Boooo
|
... | ... | @@ -232,6 +235,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.
|
... | ... | |