[Haskell-cafe] Safe Haskell and instance coherence

Simon Marlow marlowsd at gmail.com
Thu Oct 11 11:24:23 CEST 2012

On 08/10/2012 20:11, Mikhail Glushenkov wrote:
> Hello,
> It's a relatively well-known fact that GHC allows for multiple type
> class instances for the same type to coexist in a single program. This
> can be used, for example, to construct values of the type Data.Set.Set
> that violate the data structure invariant. I was mildly surprised to
> find out that this works even when Safe Haskell is turned on:
> https://gist.github.com/3854294
> Note that the warnings tell us that both instances are "[safe]" which
> gives a false sense of security.
> I couldn't find anything on the interplay between orphan instances and
> Safe Haskell both in the Haskell'12 paper and online. Is this
> something that the authors of Safe Haskell are aware of/are intending
> to fix?

A fine point.  Arguably this violates the module abstraction guarantee, 
because you are able to discover something about the implementation of 
Set by violating its assumption that the Ord instance for a given type 
is always the same.

I don't know what we should do about this.  Disallowing orphan instances 
seems a bit heavy-handed. David, Simon, any thoughts?

(can someone forward this to David Mazieres? all the email addresses I 
have for him seem to have expired :-)


More information about the Haskell-Cafe mailing list