
In that light, `coerce` then can be viewed as a more friendly but still evil version of unsafeCoerce
Coerce embodies one rather compelling improvement: it is type-sound. unsafeCoerce can cause arbitrary seg-faults etc. ‘coerce’ cannot. Call me an old-fashioned “well-typed programs don’t go wrong” man, but I think that’s a big plus. Much more than “an occasional situation improvement”.
Granted, “type-sound” doesn’t guarantee “correct”, but then it never did.
The role machinery doesn’t exactly hoist us on a dilemma – it merely exposes the dilemma that was there all the time.
Simon
From: Edward Kmett [mailto:ekmett@gmail.com]
Sent: 24 March 2014 19:11
To: Mark Lentczner
Cc: Simon Peyton Jones; libraries@haskell.org Libraries; ghc-devs@haskell.org
Subject: Re: We need to add role annotations for 7.8
Mark,
We're currently planning to retain the existing behavior of GeneralizedNewtypeDeriving with regards to Safe Haskell. That is, Safe Haskell and GND still won't mix in 7.8 due to these same security concerns.
I think a key observation with regards to GeneralizedNewtypeDeriving is with representational roles as default the new roles machinery with the representational default lets you write nothing you couldn't write before. No new security vulnerabilities are introduced. They were there all along!
We're also disabling the Safe flag on Data.Coerce. In that light, `coerce` then can be viewed as a more friendly but still evil version of unsafeCoerce. It lets you write nothing you couldn't write before with `unsafeCoerce`. I view it as merely an occasional situational improvement over the existing unsafeCoerce in that it at least enforces representational equality.
Making the default role annotation nominal comes at a very very real cost. Namely, all of generalized newtype deriving anywhere breaks, and everyone forever will have to put annotations in to fix it.
The 'backwards' representational default puts the burden on a small minority of library authors.
I'm not a huge fan of the representational machinery, in that it hoists us upon this dilemma, but given the choice between everyone paying in perpetuity and a small minority of skilled library authors adding a handful of annotations that for the most part have already been added, and which expose them to no more risk than they'd had before if they forget, I'm definitely in favor of the current solution.
-Edward
On Mon, Mar 24, 2014 at 11:26 AM, Mark Lentczner