gershomb at gmail.com
Mon Jan 14 20:53:37 CET 2013
On 1/14/13 2:42 PM, Johan Tibell wrote:
> On Mon, Jan 14, 2013 at 11:14 AM, Andrea Vezzosi <sanzhiyan at gmail.com> wrote:
>> 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.
> I was just going to say that. Changing newtypes changes instances,
> which isn't safe in the general case.
Perhaps it would be useful for data structures that need to remain
opaque/abstract to be allowed to declare such explicitly, either with
special syntax, or a distinguished pragma?
Also, I'm fond of Roman's "coerce" proposal, because I can imagine cases
where explicit declaration of wrap/unwrap functions might not
necessarily make sense. My understanding of the "lens" library, for
example, is that it builds up chains of coercions compositionally. In
such a case, even if we've eliminated the eta issue for a *single*
coercion, we'd still have it across a chain of them? Meanwhile, a single
"coerce" whose semantics were like unsafeCoerce (but only when it's
safe!) would do the job just fine at any level.
That said, I think the general direction of this proposal is great, and
I hope we can work out the kinks and get it implemented.
More information about the Glasgow-haskell-users