Hi,

Am Samstag, den 07.09.2013, 12:16 -0400 schrieb Richard Eisenberg:
> On Sep 6, 2013, at 12:47 PM, Simon Peyton-Jones <simo...@microsoft.com> wrote:
> I've always lived under the impression that changing the word
> "newtype" to "data" should have exactly 0 effect on the compile-time
> behavior of Haskell programs.

I agree, that is why I raised the point.

> Yet, you're proposing that
> 
> > module Foo (T) where   -- MkT is *not* exported
> >
> > newtype T a = MkT [a]
> 
> is different from the same with "newtype" replaced with "data". To
> wit, in the "data" version, the instance (Coercible a b => Coercible
> (T a) (T b)) would exist, but this would not be derivable in the
> "newtype" version. Right?

In the current code, the 
        instance Coercible a b => Coercible (T a) (T b)
is available for both data and newtypes, if T’s type argument has
Representational role, but independent of any constructor presence. See
the note at
https://github.com/nomeata/ghc/compare/ntclass-clean#L9R1902
for a concise and complete list of the conditions for a Coercible
instance.

> A related issue is that, even with roles, I don't think
> GeneralizedNewtypeDeriving (GND) is in the Safe Haskell subset because
> it can break abstraction barriers -- you can use GND even when a
> newtype's constructor is not in scope. The above proposal for
> coercions will have the same problem.
> 
> What to do? Map should certainly not export its constructor(s). Yet,
> we want (Coercible a b => Coercible (Map x a) (Map x b)). It seems
> that the writer of Map would have to explicitly export this instance.
> This goes at odds with the idea of "there aren't any instances of
> Coercible, really", but otherwise I have a hard time seeing how this
> would all work.


If I understood Simon’s last suggestion correctly than exporting a type
constructor with a non-Nominal role means “I am fine if you cast this
argument”. If this is not desired (e.g. maybe Ptr a is an example here),
then the library author has to annotate the type argument as Nominal.

Greetings,
Joachim

-- 
Joachim Breitner
  e-Mail: m...@joachim-breitner.de
  Homepage: http://www.joachim-breitner.de
  ICQ#: 74513189
  Jabber-ID: nome...@joachim-breitner.de

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
ghc-devs mailing list
ghc-devs@haskell.org
http://www.haskell.org/mailman/listinfo/ghc-devs

Reply via email to