[GHC] #8827: Inferring Safe mode with GeneralizedNewtypeDeriving is wrong

GHC ghc-devs at haskell.org
Fri Mar 21 13:17:02 UTC 2014


#8827: Inferring Safe mode with GeneralizedNewtypeDeriving is wrong
-------------------------------------+------------------------------------
        Reporter:  goldfire          |            Owner:
            Type:  bug               |           Status:  new
        Priority:  normal            |        Milestone:  7.8.1
       Component:  Compiler          |          Version:  7.8.1-rc2
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:  8226, 8745
-------------------------------------+------------------------------------

Comment (by simonpj):

 I think it would be helpful first for David & David to say exactly what
 they don't like about this:
 {{{
 {-# LANGUAGE Safe #-}
 module Lib( T, ... ) where

   data T a = Leaf a | Node (Tree a) (Tree a)

 {-# LANGUAGE Safe #-}
 module Client( main )

   import Lib

   newtype Age = MkAge Int

   foo :: T Age
   foo = ....

   bar :: T Int
   bar = coerce foo
 }}}
 To me this seems fine.  If (inside `Lib`) the functions over T make use of
 type-class constraints over T's parameter, then we can declare a nominal
 role:
 {{{
 {-# LANGUAGE Safe #-}
 module Lib( T, ... ) where

   data T a = Leaf a | Node (Tree a) (Tree a)
                 -- Balanced, based on Ord a
   role T nominal
 }}}
 I can see the following possible choices:

  * (A) Status quo.  Data types without role signatures get
 representational roles by default.  The above is accepted as-is

  * (B) Data types without role signatures get representational roles by
 default, except with `{-# LANGUAGE SAFE #-}` which changes the default to
 nominal.  So `Lib` will compile without complaint, but `Client` will fail.
 Presumably, `Lib` without a `Safe` pragma would be inferred as `Unsafe`,
 since `T` would have representational role.

  * (C) Data types without role signatures always get nominal roles by
 default.  That would mean that many many data types in libraries would
 have to have a role signature added, if you want to lift coercions over
 them.

 David, David, can you say what you want and why?

 Simon

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


More information about the ghc-tickets mailing list