Newtype wrappers

Brandon Allbery allbery.b at
Tue Jan 15 00:43:26 CET 2013

On Mon, Jan 14, 2013 at 5:29 PM, Johan Tibell <johan.tibell at>wrote:

> Let me rephrase: how will Simon's proposed "data constructors are in
> scope" mechanism work? For example, will
>     let xs :: Map = ...
>     in map MyNewtype xs
> behave differently if the constructors of Map are in scope or not?

If you allow deriving this without the constructors in scope, the user can
use it to violate the invariant (by the new type causing Map to think it is
sorted differently than it is, because there is a different Ord constraint).

Requiring the constructors to be in scope doesn't actually prevent this,
but does give the user some chance to do something about it.  Meanwhile
something that deliberately hides its constructors to preserve an invariant
can't suddenly have that invariant violated by an errant use of this

brandon s allbery kf8nh                               sine nomine associates
allbery.b at                                  ballbery at
unix, openafs, kerberos, infrastructure, xmonad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Glasgow-haskell-users mailing list