Last active
December 21, 2015 05:49
-
-
Save strager/6259516 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE ExistentialQuantification #-} | |
| import Data.Typeable (Typeable, TypeRep, typeOf) | |
| import Unsafe.Coerce (unsafeCoerce) | |
| data Magic = forall a. Magic | |
| (a -> a -> Bool) | |
| TypeRep | |
| a | |
| instance Eq Magic where | |
| Magic eq typeRepX x == Magic _ typeRepY y | |
| = typeRepX == typeRepY && x `eq` unsafeCoerce y | |
| magic :: (Eq a, Typeable a) => a -> Magic | |
| magic x = Magic (==) (typeOf x) x | |
| -- > magic (10::Int) == magic ("hello"::String) | |
| -- False | |
| -- > magic (10::Int) == magic (10::Int) | |
| -- True | |
| -- > magic (10::Int) == magic (10::Double) | |
| -- False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment