diff options
author | David Feuer <david.feuer@gmail.com> | 2017-03-30 13:30:52 -0400 |
---|---|---|
committer | David Feuer <David.Feuer@gmail.com> | 2017-03-30 13:30:54 -0400 |
commit | 69f070d8e4d6043937e3405675ac911448bfcb44 (patch) | |
tree | 022823fcccf914836dfd804e2facfd977492a8fa /testsuite/tests/generics | |
parent | ff7094e5a80435ff68490c725029e762913a72d3 (diff) | |
download | haskell-69f070d8e4d6043937e3405675ac911448bfcb44.tar.gz |
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
Diffstat (limited to 'testsuite/tests/generics')
-rw-r--r-- | testsuite/tests/generics/T10604/T10604_deriving.stderr | 128 |
1 files changed, 55 insertions, 73 deletions
diff --git a/testsuite/tests/generics/T10604/T10604_deriving.stderr b/testsuite/tests/generics/T10604/T10604_deriving.stderr index 6862ff5adc..59be21fd45 100644 --- a/testsuite/tests/generics/T10604/T10604_deriving.stderr +++ b/testsuite/tests/generics/T10604/T10604_deriving.stderr @@ -3,28 +3,17 @@ Derived class instances: instance GHC.Generics.Generic (T10604_deriving.Empty a) where GHC.Generics.from x - = GHC.Generics.M1 - (case x of { - _ -> GHC.Err.error - "No generic representation for empty datatype Empty" }) - GHC.Generics.to (GHC.Generics.M1 x) - = case x of { - _ -> GHC.Err.error "No values for empty datatype Empty" } + = GHC.Generics.M1 (case x of { x -> case x of }) + GHC.Generics.to (GHC.Generics.M1 x) = case x of { x -> case x of } instance GHC.Generics.Generic1 GHC.Types.Bool T10604_deriving.Empty where GHC.Generics.from1 x - = GHC.Generics.M1 - (case x of { - _ -> GHC.Err.error - "No generic representation for empty datatype Empty" }) - GHC.Generics.to1 (GHC.Generics.M1 x) - = case x of { - _ -> GHC.Err.error "No values for empty datatype Empty" } + = GHC.Generics.M1 (case x of { x -> case x of }) + GHC.Generics.to1 (GHC.Generics.M1 x) = case x of { x -> case x of } instance GHC.Base.Functor (T10604_deriving.Proxy *) where - GHC.Base.fmap f T10604_deriving.Proxy = T10604_deriving.Proxy - (GHC.Base.<$) z T10604_deriving.Proxy = T10604_deriving.Proxy + GHC.Base.fmap _ = GHC.Prim.coerce instance forall k (a :: k). GHC.Generics.Generic (T10604_deriving.Proxy k a) where @@ -56,8 +45,7 @@ Derived class instances: (GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.K1 g1))) -> T10604_deriving.Wrap g1 } - instance GHC.Generics.Generic1 - (* -> *) T10604_deriving.Wrap where + instance GHC.Generics.Generic1 (* -> *) T10604_deriving.Wrap where GHC.Generics.from1 x = GHC.Generics.M1 (case x of { @@ -250,35 +238,25 @@ Derived type family instances: 'GHC.Generics.DecidedLazy) (GHC.Generics.Rec0 * - (T10604_deriving.Proxy - (* -> *) a)))) + (T10604_deriving.Proxy (* -> *) a)))) type GHC.Generics.Rep1 (* -> *) T10604_deriving.Wrap = GHC.Generics.D1 - (* -> *) - ('GHC.Generics.MetaData - "Wrap" - "T10604_deriving" - "main" - 'GHC.Types.False) - (GHC.Generics.C1 - (* -> *) - ('GHC.Generics.MetaCons - "Wrap" - 'GHC.Generics.PrefixI - 'GHC.Types.False) - (GHC.Generics.S1 - (* -> *) - ('GHC.Generics.MetaSel - ('GHC.Base.Nothing - GHC.Types.Symbol) - 'GHC.Generics.NoSourceUnpackedness - 'GHC.Generics.NoSourceStrictness - 'GHC.Generics.DecidedLazy) - (GHC.Generics.Rec1 - (* -> *) - (T10604_deriving.Proxy - (* - -> *))))) + (* -> *) + ('GHC.Generics.MetaData + "Wrap" "T10604_deriving" "main" 'GHC.Types.False) + (GHC.Generics.C1 + (* -> *) + ('GHC.Generics.MetaCons + "Wrap" 'GHC.Generics.PrefixI 'GHC.Types.False) + (GHC.Generics.S1 + (* -> *) + ('GHC.Generics.MetaSel + ('GHC.Base.Nothing GHC.Types.Symbol) + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + (GHC.Generics.Rec1 + (* -> *) (T10604_deriving.Proxy (* -> *))))) type GHC.Generics.Rep (T10604_deriving.Wrap2 k a) = GHC.Generics.D1 * ('GHC.Generics.MetaData @@ -308,34 +286,32 @@ Derived type family instances: (k -> *) a))))) type GHC.Generics.Rep1 (k -> *) (T10604_deriving.Wrap2 k) = GHC.Generics.D1 - (k -> *) - ('GHC.Generics.MetaData - "Wrap2" - "T10604_deriving" - "main" - 'GHC.Types.False) - (GHC.Generics.C1 - (k -> *) - ('GHC.Generics.MetaCons - "Wrap2" - 'GHC.Generics.PrefixI - 'GHC.Types.False) - (GHC.Generics.S1 - (k -> *) - ('GHC.Generics.MetaSel - ('GHC.Base.Nothing - GHC.Types.Symbol) - 'GHC.Generics.NoSourceUnpackedness - 'GHC.Generics.NoSourceStrictness - 'GHC.Generics.DecidedLazy) - ((GHC.Generics.:.:) - * - (k -> *) - (T10604_deriving.Proxy *) - (GHC.Generics.Rec1 - (k -> *) - (T10604_deriving.Proxy - (k -> *)))))) + (k -> *) + ('GHC.Generics.MetaData + "Wrap2" + "T10604_deriving" + "main" + 'GHC.Types.False) + (GHC.Generics.C1 + (k -> *) + ('GHC.Generics.MetaCons + "Wrap2" + 'GHC.Generics.PrefixI + 'GHC.Types.False) + (GHC.Generics.S1 + (k -> *) + ('GHC.Generics.MetaSel + ('GHC.Base.Nothing GHC.Types.Symbol) + 'GHC.Generics.NoSourceUnpackedness + 'GHC.Generics.NoSourceStrictness + 'GHC.Generics.DecidedLazy) + ((GHC.Generics.:.:) + * + (k -> *) + (T10604_deriving.Proxy *) + (GHC.Generics.Rec1 + (k -> *) + (T10604_deriving.Proxy (k -> *)))))) type GHC.Generics.Rep (T10604_deriving.SumOfProducts k a) = GHC.Generics.D1 * @@ -542,3 +518,9 @@ Derived type family instances: * GHC.Types.Int)))) + +==================== Filling in method body ==================== +GHC.Base.Functor [T10604_deriving.Proxy *] + GHC.Base.<$ = GHC.Base.$dm<$ @T10604_deriving.Proxy * + + |