Newtype wrappers

Simon Peyton-Jones simonpj at microsoft.com
Mon Jan 14 22:19:12 CET 2013


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:sanzhiyan at 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 <simonpj at microsoft.com<mailto:simonpj at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20130114/a801cd62/attachment.htm>


More information about the Glasgow-haskell-users mailing list