... | ... | @@ -33,66 +33,82 @@ 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:
|
|
|
|
|
|
```
|
|
|
instanceFunctorFoowhere
|
|
|
```haskell
|
|
|
instance Functor Foo where
|
|
|
fmap = liftM
|
|
|
-- 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... -}
|
|
|
```
|
|
|
-- or alternatively:
|
|
|
-- fmap = m >>= pure . f
|
|
|
|
|
|
instance Applicative Foo where
|
|
|
-- 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 -}
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
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 ...)`
|
|
|
|
|
|
|
|
|
A side-effect of the AMP is that `Alternative` became a super-class of `MonadPlus`. The easy remedy:
|
|
|
|
|
|
```
|
|
|
instanceAlternativeFoowhere(<|>)= mplus
|
|
|
```haskell
|
|
|
instance Alternative Foo where
|
|
|
(<|>) = mplus
|
|
|
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.
|
|
|
|
|
|
```
|
|
|
instanceAlternativeFoowhere
|
|
|
empty ={- move definition of `mzero` here -}(<|>)={- move definition of `mplus` here -}instanceMonadPlusFoo-- NB: starting with `base-4.8`: no need to override methods here!
|
|
|
```haskell
|
|
|
instance Alternative Foo where
|
|
|
empty = {- move definition of `mzero` here -}
|
|
|
(<|>) = {- move definition of `mplus` here -}
|
|
|
|
|
|
instance MonadPlus Foo -- NB: starting with `base-4.8`: no need to override methods here!
|
|
|
```
|
|
|
|
|
|
#### GHC says `No instance for (Foldable ...) arising from the use of...`
|
|
|
|
|
|
|
|
|
Some functions in the Prelude were generalised to `Foldable`s in the implementation of the FTP. This can lead to type-inference problems for code making use of `-XOverloadedStrings`, in which code like e.g.
|
|
|
|
|
|
```
|
|
|
{-# LANGUAGE OverloadedStrings #-}main::IO()main= print ('I'`elem`"team")
|
|
|
```
|
|
|
```haskell
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
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
|
... | ... | @@ -114,7 +130,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`
|
... | ... | @@ -122,14 +137,17 @@ This can be fixed by helping GHC's type-inference to pin down `"team"` to `[Char |
|
|
|
|
|
With `base-4.8`, the `Prelude` re-exports a few more entities from modules such as `Data.Monoid` and `Control.Applicative`. For example, the following module
|
|
|
|
|
|
```
|
|
|
moduleFoo(Int,Word,Monoid(..))whereimportData.MonoidimportData.Word-- import Prelude
|
|
|
```
|
|
|
```haskell
|
|
|
module Foo (Int, Word, Monoid(..)) where
|
|
|
|
|
|
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’
|
... | ... | @@ -141,25 +159,30 @@ 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.
|
|
|
|
|
|
|
|
|
A more robust way (that works when the trick above doesn't work) to convince GHC without `-XCPP` to suppress redundancy-warnings is by referencing a module-prefixed entity form the respective module at least once. In the example below, `pure` is referenced just once via `A.pure`, thereby marking the `import` essential:
|
|
|
|
|
|
```
|
|
|
importControl.Applicativeas A (Applicative(..))dataMaybe' a =Nothing'|Just' a
|
|
|
```haskell
|
|
|
import Control.Applicative as A (Applicative(..))
|
|
|
|
|
|
data Maybe' a = Nothing' | Just' a
|
|
|
|
|
|
instance Functor Maybe' where
|
|
|
fmap f (Just' v) = Just' (f v)
|
|
|
fmap _ Nothing' = Nothing'
|
|
|
|
|
|
instanceFunctorMaybe'where
|
|
|
fmap f (Just' v)=Just'(f v)
|
|
|
fmap _Nothing'=Nothing'instanceApplicativeMaybe'where
|
|
|
pure =Just'
|
|
|
f1 <*> f2 = f1 >>=\v1 -> f2 >>=(pure . v1)instanceMonadMaybe'whereNothing'>>=_=Nothing'Just' x >>= f = f x
|
|
|
instance Applicative Maybe' where
|
|
|
pure = Just'
|
|
|
f1 <*> f2 = f1 >>= \v1 -> f2 >>= (pure . v1)
|
|
|
|
|
|
return =A.pure -- NB: This definition is redundant since GHC 7.10/base-4.8
|
|
|
instance Monad Maybe' where
|
|
|
Nothing' >>= _ = Nothing'
|
|
|
Just' x >>= f = f x
|
|
|
|
|
|
return = A.pure -- NB: This definition is redundant since GHC 7.10/base-4.8
|
|
|
```
|
|
|
|
|
|
### `deepseq-1.4.0.0` (& `deepseq-1.4.1.0`)
|
... | ... | @@ -167,14 +190,13 @@ instanceFunctorMaybe'where |
|
|
|
|
|
The default method implementation has been changed, so instances defined via
|
|
|
|
|
|
```haskell
|
|
|
instance NFData Foo
|
|
|
```
|
|
|
instanceNFDataFoo
|
|
|
```
|
|
|
|
|
|
|
|
|
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
|
... | ... | @@ -182,39 +204,38 @@ 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
|
|
|
|
|
|
```
|
|
|
instanceNFDataFoowhere rnf x = seq x ()
|
|
|
```haskell
|
|
|
instance NFData Foo where rnf x = seq x ()
|
|
|
```
|
|
|
|
|
|
|
|
|
instead of relying on the default method implementation.
|
|
|
|
|
|
|
|
|
For more details (and how to use the new facilities) see Haddock documentation of [ hackage:deepseq](http://hackage.haskell.org/package/deepseq)
|
|
|
|
|
|
### `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).
|
|
|
|
|
|
|
|
|
Old representation:
|
|
|
|
|
|
```haskell
|
|
|
data Integer
|
|
|
= S# Int# -- ^ \"small\" integers fitting into an 'Int#'
|
|
|
| J# Int# ByteArray# -- ^ \"big\" integers (legal to be used to represent 'Int#'-range)
|
|
|
```
|
|
|
dataInteger=S#Int#-- ^ \"small\" integers fitting into an 'Int#'|J#Int#ByteArray#-- ^ \"big\" integers (legal to be used to represent 'Int#'-range)
|
|
|
```
|
|
|
|
|
|
|
|
|
New representation:
|
|
|
|
|
|
```
|
|
|
dataInteger=S#Int#-- ^ iff value in @[minBound::'Int', maxBound::'Int']@ range|Jp#!BigNat-- ^ iff value in @]maxBound::'Int', +inf[@ range|Jn#!BigNat-- ^ iff value in @]-inf, minBound::'Int'[@ range
|
|
|
```haskell
|
|
|
data Integer
|
|
|
= S# Int# -- ^ iff value in @[minBound::'Int', maxBound::'Int']@ range
|
|
|
| Jp# !BigNat -- ^ iff value in @]maxBound::'Int', +inf[@ range
|
|
|
| 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
|
... | ... | @@ -222,7 +243,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.
|
... | ... | @@ -231,7 +251,6 @@ There are a number of API changes in this release of Template Haskell. |
|
|
|
|
|
### `time-1.5.0.1`
|
|
|
|
|
|
|
|
|
The major breaking change in [ hackage:time-1.5.0.1](http://hackage.haskell.org/package/time-1.5.0.1) is not requiring `old-locale` anymore and providing its own locale-type.
|
|
|
|
|
|
|
... | ... | @@ -239,12 +258,11 @@ See [ https://github.com/bos/aeson/commit/730a8c42b75f38e241da39933b03735a7c9055 |
|
|
|
|
|
### `array-0.5.1.0`
|
|
|
|
|
|
|
|
|
In 0.5.0.0, one could derive Data.Array.Unboxed instances for newtype Int's, Word64's etc.:
|
|
|
|
|
|
```haskell
|
|
|
newtype N = MkN Word64
|
|
|
deriving (IArray UArray)
|
|
|
```
|
|
|
newtypeN=MkNWord64deriving(IArrayUArray)
|
|
|
```
|
|
|
|
|
|
|
|
|
After [ https://ghc.haskell.org/trac/ghc/ticket/9220](https://ghc.haskell.org/trac/ghc/ticket/9220) changed the UArray role to nominal, one has to manually create instances (see [ http://stackoverflow.com/a/40988667/69663](http://stackoverflow.com/a/40988667/69663) for an example). |