[Haskell-cafe] Any precedent or plan for guaranteed-safe Eq and Ord instances?
Tue Oct 1 20:13:43 UTC 2013
Normally, we don't worry *too* much about incorrect instances of standard
classes (Num, Eq, Ord) etc. They make the user's program wrong, but they
don't compromise the type system.
Unfortunately, with the LVish parallel programming library we do have a
situation where incorrect instances of Eq and Ord can cause the "types to
lie". In particular, something that claims to be a pure, non-IO type, can
actually yield a different result on different runs, including throwing
exceptions on some runs but not others.
So what's the best way to lock down "SafeEq" and "SafeOrd" instances,
taking control away from the user (at least with -XSafe is turned on)?
We could derive our own SafeEq and SafeOrd instances based on GHC.Generics.
BUT, that only helps if we can forbid the user from writing their own
incorrect Generics instances when Safe Haskell is turned on. It looks like
GHC.Generics is currently marked as "TrustWorthy":
So.... could we get GHC.Generics marked as "Unsafe" and enable some more
limited interface that is "Trustworthy"? (Allowing the user ONLY to do
This would be similar to the new policy in GHC 7.8 of only allowing derived
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe