[GHC] #13598: role annotation for newtype (partially?) ignored?

GHC ghc-devs at haskell.org
Thu Apr 20 15:33:14 UTC 2017


#13598: role annotation for newtype (partially?) ignored?
-------------------------------------+-------------------------------------
        Reporter:  edsko             |                Owner:  (none)
            Type:  bug               |               Status:  closed
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.1-rc2
      Resolution:  invalid           |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 > even though I was not using those constructors anywhere in that code

 The rationale (explained in the paper) is this. Without the built-in
 support for `Coercible` you could do everything by unpacking and repacking
 newtype constructors.  Eg
 {{{
 newtype Age = MkAge Pos
 newtype Pos = MkPos Int

 foo1, foo2 :: Age -> Int
 foo1 (MkAge (MkPos n)) = n
 foo2 n = coerce n
 }}}
 The `foo1` route requires `MkAge` and `MkPos` to be in scope; and you
 might hide them specifically to prevent you looking inside the abstraction
 (e.g. you might anticipate changing the representation of `Age` in the
 future).  If so, then for the same reasons `foo2` should fail if `MkAge`
 or `MkPos` are not in scope.

 Does that help explain?   Should we add something to the user manual?

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


More information about the ghc-tickets mailing list