Skip to content

Instantly share code, notes, and snippets.

@bitonic
Created January 17, 2015 14:13
Show Gist options
  • Save bitonic/481b595d77e4e6a80278 to your computer and use it in GitHub Desktop.
Save bitonic/481b595d77e4e6a80278 to your computer and use it in GitHub Desktop.
The dangers of incoherence
module A where
newtype MyInt = MyInt {unMyInt :: Int}
deriving (Show)
module B where
import qualified Data.Map as Map
import Debug.Trace
import A
instance Eq MyInt where
MyInt x == MyInt y = y == x
instance Ord MyInt where
compare (MyInt x) (MyInt y) = compare y x
buildMap :: Map.Map MyInt MyInt
buildMap = Map.fromList $ zip (map MyInt [1..10]) (map MyInt [10,9..1])
module C where
import qualified Data.Map as Map
import A
instance Eq MyInt where
MyInt x == MyInt y = x == y
instance Ord MyInt where
compare (MyInt x) (MyInt y) = compare x y
modifyMap :: Map.Map MyInt MyInt -> Map.Map MyInt MyInt
modifyMap = Map.insert (MyInt 0) (MyInt 0)
module D where
import qualified Data.Map as Map
import A
import qualified B
import qualified C
main :: IO ()
main =
print $ map unMyInt $ map fst $ Map.toAscList $ C.modifyMap $ B.buildMap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment