... | ... | @@ -33,13 +33,12 @@ The major changes include the implementation of the *Functor/Applicative/Monad-P |
|
|
|
|
|
If GHC complains that
|
|
|
|
|
|
```wiki
|
|
|
```
|
|
|
Foo.hs:7:10:
|
|
|
No instance for (Applicative Foo) arising from the superclasses of an instance declaration
|
|
|
In the instance declaration for ‘Monad Foo’
|
|
|
```
|
|
|
|
|
|
|
|
|
then an easy way to fix this error is by defining an `Applicative` (and possibly a `Functor`) instance:
|
|
|
|
|
|
|
... | ... | @@ -68,13 +67,19 @@ instance Monad Foo where |
|
|
{- ...retain other previous definitions... -}
|
|
|
```
|
|
|
|
|
|
instance Monad Foo where
|
|
|
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)
|
|
|
|
|
|
|
... | ... | @@ -93,7 +98,6 @@ instance Alternative Foo where |
|
|
empty = mzero
|
|
|
```
|
|
|
|
|
|
|
|
|
If pre-AMP compatibility is not a requirement, it's better to define `MonadPlus` in terms of `Alternative` as this corresponds to the superclass relationship and allows to omit the method definitions in `MonadPlus`, i.e.
|
|
|
|
|
|
|
... | ... | @@ -119,10 +123,13 @@ main :: IO () |
|
|
main = print ('I' `elem` "team")
|
|
|
```
|
|
|
|
|
|
main :: IO ()
|
|
|
main = print ('I' `elem` "team")
|
|
|
```
|
|
|
|
|
|
will let GHC spit out the intimidating complaint that
|
|
|
|
|
|
```wiki
|
|
|
```
|
|
|
Foo.hs:4:19:
|
|
|
No instance for (Foldable t0) arising from a use of ‘elem’
|
|
|
The type variable ‘t0’ is ambiguous
|
... | ... | @@ -144,7 +151,6 @@ Foo.hs:4:26: |
|
|
In the expression: print ('I' `elem` "team")
|
|
|
```
|
|
|
|
|
|
|
|
|
This can be fixed by helping GHC's type-inference to pin down `"team"` to `[Char]`, either by adding a `:: String` to the string literal, or (for short literals) by using list-syntax (i.e. `['t','e','a','m']`).
|
|
|
|
|
|
#### GHC says `The import of ... is redundant`
|
... | ... | @@ -162,10 +168,14 @@ import Data.Word |
|
|
-- import Prelude
|
|
|
```
|
|
|
|
|
|
import Data.Monoid
|
|
|
import Data.Word
|
|
|
-- import Prelude
|
|
|
```
|
|
|
|
|
|
will result in two redundant import warnings with GHC 7.10.1 (under `-Wall`):
|
|
|
|
|
|
```wiki
|
|
|
```
|
|
|
foo.hs:3:1: Warning:
|
|
|
The import of ‘Data.Monoid’ is redundant
|
|
|
except perhaps to import instances from ‘Data.Monoid’
|
... | ... | @@ -177,10 +187,8 @@ foo.hs:4:1: Warning: |
|
|
To import instances alone, use: import Data.Word()
|
|
|
```
|
|
|
|
|
|
|
|
|
This `import Prelude`-trick, however, doesn't work when explicit import lists are used. In that case, `qualified` imports can be used if `-XCPP` needs to be avoided at all costs.
|
|
|
|
|
|
|
|
|
One obvious way to silence such warnings is use `-XCPP`. However, there's also a less-known trick/hack to moving the implicit `import Prelude` into an explicit one after all `base`-imports. In the code example above just de-comment the `-- import Prelude` line.
|
|
|
|
|
|
|
... | ... | @@ -222,7 +230,7 @@ instance NFData Foo |
|
|
|
|
|
will now result in the following compile error (unless a `Generic` instance happens to exist):
|
|
|
|
|
|
```wiki
|
|
|
```
|
|
|
Foo.hs:5:10:
|
|
|
No instance for (GHC.Generics.Generic Foo) arising from a use of ‘Control.DeepSeq.$gdmrnf’
|
|
|
In the expression: Control.DeepSeq.$gdmrnf
|
... | ... | @@ -230,7 +238,6 @@ Foo.hs:5:10: |
|
|
In the instance declaration for ‘NFData Foo’
|
|
|
```
|
|
|
|
|
|
|
|
|
The easiest way make code work again with `deepseq-1.4.0.0` which was relying on the pre-1.4 default method implementation of `rnf` is to explicitly define `rnf` like so
|
|
|
|
|
|
|
... | ... | @@ -238,7 +245,6 @@ The easiest way make code work again with `deepseq-1.4.0.0` which was relying on |
|
|
instance NFData Foo where rnf x = seq x ()
|
|
|
```
|
|
|
|
|
|
|
|
|
instead of relying on the default method implementation.
|
|
|
|
|
|
|
... | ... | @@ -246,7 +252,6 @@ For more details (and how to use the new facilities) see Haddock documentation o |
|
|
|
|
|
### `integer-gmp-1.0.0.0`
|
|
|
|
|
|
|
|
|
The internal representation for `Integer`s has changed. Code only referencing the `S#` constructor should not be affected. The `J#` constructor however has been replaced by two new `Jp#` and `Jn#` constructors (see below).
|
|
|
|
|
|
|
... | ... | @@ -271,7 +276,6 @@ data Integer |
|
|
| Jn# !BigNat -- ^ iff value in @]-inf, minBound::'Int'[@ range
|
|
|
```
|
|
|
|
|
|
|
|
|
Please note that the new representation is now **stricter regarding internal invariants** (note the if-and-only-ifs `iff`s in the comments above). For more details, see
|
|
|
|
|
|
- [wiki:Design/IntegerGmp2](design/integer-gmp2) and
|
... | ... | @@ -279,7 +283,6 @@ Please note that the new representation is now **stricter regarding internal inv |
|
|
|
|
|
### `template-haskell-2.10.0.0`
|
|
|
|
|
|
|
|
|
There are a number of API changes in this release of Template Haskell.
|
|
|
|
|
|
- The `Pred` type (recall `type Cxt = [Pred]`) is now a synonym of `Type`, to allow TH to work with the `ConstraintKinds` extension. There is thus a new `EqualityT` constructor of `Type` that represents `~`. The `classP` and `equalP` functions from `TH.Lib` remain, but are deprecated.
|
... | ... | |