[GHC] #13117: Derived functor instance for void types handles errors badly

GHC ghc-devs at haskell.org
Thu Mar 30 17:35:17 UTC 2017


#13117: Derived functor instance for void types handles errors badly
-------------------------------------+-------------------------------------
        Reporter:  dfeuer            |                Owner:  dfeuer
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.1
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #7401             |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by David Feuer <David.Feuer@…>):

 In [changeset:"69f070d8e4d6043937e3405675ac911448bfcb44/ghc" 69f070d/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="69f070d8e4d6043937e3405675ac911448bfcb44"
 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
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13117#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list