[commit: ghc] master: Deriving for phantom and empty types (69f070d)
git at git.haskell.org
git at git.haskell.org
Thu Mar 30 17:35:24 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/69f070d8e4d6043937e3405675ac911448bfcb44/ghc
>---------------------------------------------------------------
commit 69f070d8e4d6043937e3405675ac911448bfcb44
Author: David Feuer <david.feuer at gmail.com>
Date: Thu Mar 30 13:30:52 2017 -0400
Deriving for phantom and empty types
Make `Functor`, `Foldable`, and `Traversable` take advantage
of the case where the type parameter is phantom. In this case,
* `fmap _ = coerce`
* `foldMap _ _ = mempty`
* `traverse _ x = pure (coerce x)`
For the sake of consistency and especially simplicity, make other types
with no data constructors behave the same:
* `fmap _ x = case x of`
* `foldMap _ _ = mempty`
* `traverse _ x = pure (case x of)`
Similarly, for `Generic`,
* `to x = case x of`
* `from x = case x of`
Give all derived methods for types without constructors appropriate
arities. For example,
```
compare _ _ = error ...
```
rather than
```
compare = error ...
```
Fixes #13117 and #13328
Reviewers: austin, bgamari, RyanGlScott
Reviewed By: RyanGlScott
Subscribers: ekmett, RyanGlScott, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3374
>---------------------------------------------------------------
69f070d8e4d6043937e3405675ac911448bfcb44
compiler/typecheck/TcGenDeriv.hs | 114 ++++++-----
compiler/typecheck/TcGenFunctor.hs | 216 +++++++++++++++++----
compiler/typecheck/TcGenGenerics.hs | 15 +-
docs/users_guide/8.4.1-notes.rst | 78 ++++++++
docs/users_guide/glasgow_exts.rst | 74 ++++++-
docs/users_guide/index.rst | 1 +
testsuite/tests/deriving/should_compile/all.T | 5 +
.../deriving/should_compile/drv-empty-data.hs | 19 ++
.../deriving/should_compile/drv-empty-data.stderr | 68 +++++++
.../tests/deriving/should_compile/drv-phantom.hs | 12 ++
.../deriving/should_compile/drv-phantom.stderr | 18 ++
.../tests/generics/T10604/T10604_deriving.stderr | 128 ++++++------
testsuite/tests/perf/compiler/T13056.hs | 4 +
13 files changed, 584 insertions(+), 168 deletions(-)
Diff suppressed because of size. To see it, use:
git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc 69f070d8e4d6043937e3405675ac911448bfcb44
More information about the ghc-commits
mailing list