Skip to content

Instantly share code, notes, and snippets.

@aavogt
Created April 1, 2016 23:18
Show Gist options
  • Select an option

  • Save aavogt/8e6a32595087ec9ed30de5b7226bb0df to your computer and use it in GitHub Desktop.

Select an option

Save aavogt/8e6a32595087ec9ed30de5b7226bb0df to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE GADTs #-}
module A where
a0 :: EqBox A
a0 = EqBox A
data EqBox a where EqBox :: Eq a => a -> EqBox a
data A = A
instance Eq a where
(==) _ _ = False
import A
instance Eq A where
(==) _ _ = True
a1 :: EqBox A
a1 = EqBox A
f :: EqBox a -> EqBox a -> Bool
f (EqBox a) (EqBox b) = a == b
main = do
print $ f a0 a1
print $ f a1 a0
-- main prints True\nFalse, saying that the Eq dictionary from the second argument is used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment