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
Showing
- compiler/typecheck/TcGenDeriv.hs 70 additions, 44 deletionscompiler/typecheck/TcGenDeriv.hs
- compiler/typecheck/TcGenFunctor.hs 177 additions, 39 deletionscompiler/typecheck/TcGenFunctor.hs
- compiler/typecheck/TcGenGenerics.hs 5 additions, 10 deletionscompiler/typecheck/TcGenGenerics.hs
- docs/users_guide/8.4.1-notes.rst 78 additions, 0 deletionsdocs/users_guide/8.4.1-notes.rst
- docs/users_guide/glasgow_exts.rst 72 additions, 2 deletionsdocs/users_guide/glasgow_exts.rst
- docs/users_guide/index.rst 1 addition, 0 deletionsdocs/users_guide/index.rst
- testsuite/tests/deriving/should_compile/all.T 5 additions, 0 deletionstestsuite/tests/deriving/should_compile/all.T
- testsuite/tests/deriving/should_compile/drv-empty-data.hs 19 additions, 0 deletionstestsuite/tests/deriving/should_compile/drv-empty-data.hs
- testsuite/tests/deriving/should_compile/drv-empty-data.stderr 68 additions, 0 deletions...suite/tests/deriving/should_compile/drv-empty-data.stderr
- testsuite/tests/deriving/should_compile/drv-phantom.hs 12 additions, 0 deletionstestsuite/tests/deriving/should_compile/drv-phantom.hs
- testsuite/tests/deriving/should_compile/drv-phantom.stderr 18 additions, 0 deletionstestsuite/tests/deriving/should_compile/drv-phantom.stderr
- testsuite/tests/generics/T10604/T10604_deriving.stderr 55 additions, 73 deletionstestsuite/tests/generics/T10604/T10604_deriving.stderr
- testsuite/tests/perf/compiler/T13056.hs 4 additions, 0 deletionstestsuite/tests/perf/compiler/T13056.hs
Loading
Please register or sign in to comment