Have you considered the effect on types like Data.Set that use the uniqueness 
of typeclass instances to maintain invariants? e.g. even when we have "newtype 
X = X Y" coercing "Set X" to "Set Y" can produce a tree with the wrong shape 
for the Ord instance of Y.

Good point. I should add this.  The wrapper should only work if the relevant 
data constructors are in scope; rather like GHC's existing auto-unwrapping on 
foreign calls 
(http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi.html#ffi-newtype-io)

So then hiding the data constructor maintains the abstraction as indeed it 
should.

Simon

From: Andrea Vezzosi [mailto:sanzhi...@gmail.com]
Sent: 14 January 2013 19:15
To: Simon Peyton-Jones
Cc: GHC users
Subject: Re: Newtype wrappers

On Mon, Jan 14, 2013 at 7:09 PM, Simon Peyton-Jones 
<simo...@microsoft.com<mailto:simo...@microsoft.com>> wrote:
Friends

I'd like to propose a way to "promote" newtypes over their enclosing type.  
Here's the writeup
          http://hackage.haskell.org/trac/ghc/wiki/NewtypeWrappers

Any comments?  Below is the problem statement, taken from the above page.

Have you considered the effect on types like Data.Set that use the uniqueness 
of typeclass instances to maintain invariants? e.g. even when we have "newtype 
X = X Y" coercing "Set X" to "Set Y" can produce a tree with the wrong shape 
for the Ord instance of Y.



-- Andrea
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to