... | ... | @@ -45,15 +45,21 @@ then an easy way to fix this error is by defining an `Applicative` (and possibly |
|
|
```
|
|
|
instanceFunctorFoowhere
|
|
|
fmap = liftM
|
|
|
-- or alternatively:-- fmap = m >>= pure . finstanceApplicativeFoowhere
|
|
|
pure ={- move the definition of `return` from the `Monad` instance -}(<*>)= ap {- defined in Control.Monad -}-- or alternatively:-- f1 <*> f2 = f1 >>= \v1 -> f2 >>= (pure . v1)instanceMonadFoowhere
|
|
|
return = pure {- definition moved to `Applicative(pure)` -}{- ...retain other previous definitions... -}
|
|
|
-- or alternatively:-- fmap = m >>= pure . finstanceApplicativeFoowhere-- NB: DO NOT USE `pure = return`
|
|
|
pure ={- move the definition of `return` from the `Monad` instance here -}(<*>)= ap {- defined in Control.Monad -}-- or alternatively:-- f1 <*> f2 = f1 >>= \v1 -> f2 >>= (pure . v1)-- NB: DO NOT USE `(*>) = (>>)`(*>)={- move the definition of `>>` from the `Monad` instance here -}instanceMonadFoowhere
|
|
|
return = pure {- definition moved to `Applicative(pure)` -}(>>)=(*>){- definition moved to `Applicative((*>))` -}{- ...retain other previous definitions... -}
|
|
|
```
|
|
|
|
|
|
|
|
|
Starting with GHC 7.10, defining `Monad(return)` is optional (with the default implementation `return = pure`). For code not required to be compatible with GHC versions prior to GHC 7.10 it's recommended to omit the explicit `return` definition.
|
|
|
|
|
|
|
|
|
Moreover, in order to avoid surprising performance issues with `Traversable`, `(>>)` should be defined in terms of `(*>)`, and with `(*>)` optionally being overridden by an optimised implementation.
|
|
|
|
|
|
|
|
|
See also [Proposal/MonadOfNoReturn](proposal/monad-of-no-return)
|
|
|
|
|
|
|
|
|
For more details see [ AMP Proposal: Future-proofing current code](https://www.haskell.org/haskellwiki/Functor-Applicative-Monad_Proposal#Future-proofing_current_code).
|
|
|
|
|
|
#### GHC says `No instance for (Alternative ...)`
|
... | ... | |