Skip to content

Instantly share code, notes, and snippets.

@depp
depp / Enum.hs
Created April 1, 2012 23:07
Demonstration of incorrect (Enum x, Enum y) => Enum (x, y) instance
-- See http://stackoverflow.com/questions/9967790/instance-in-haskell
instance (Enum x, Enum y) => Enum (x, y) where
fromEnum (x,y) =
k^2 + 2*j + if permuted then 1 else 0
where
k = max (fromEnum x) (fromEnum y)
j = min (fromEnum x) (fromEnum y)
permuted = (fromEnum y) > (fromEnum x)
toEnum n =