default roles

David Menendez dave
Fri Oct 11 16:33:09 UTC 2013


On Thu, Oct 10, 2013 at 10:09 PM, Edward Kmett <ekmett at gmail.com> wrote:

> Wait, that sounds like it induces bad semantics.
>
> Can't we use that as yet another way to attack the sanctity of Set?
>
> class Ord a => Foo a where
>   badInsert :: a -> Set a -> Set a
>
> instance Foo Int where
>   badInsert = insert
>
> newtype Bar = Bar Int deriving (Eq,Foo)
>
> instance Ord Bar where
>   compare (Bar x) (Bar y) = compare y x
>
> Now you can badInsert into a Set.
>
> If that is still in play then even with all the roles machinery then GND
> doesn't pass the restrictions of "SafeHaskell". =(
>

It seems like doing GND for an instance is okay as long as it's done for
all the superclasses as well.

Alternately, what about keeping non-specialized versions of the instance
code around? Like, if we have (in pseudocode):

    ordint :: OrdInstance Int
    fooint :: FooInstance Int
    ordbar :: OrdInstance Bar

instead of saying foobar = coerce fooint, we could use

    fooint_ordint :: OrdInstance Int -> FooInstance Int

and set foobar = coerce (foointordint (coerce ordbar)

That seems like it would be correct, albeit less efficient. We can still
use coerce fooint for newtype of Int that also use GND for the Ord instance.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20131011/31d88f43/attachment.html>



More information about the Glasgow-haskell-users mailing list