Skip to content

Instantly share code, notes, and snippets.

View leftaroundabout's full-sized avatar

Justus Sagemüller leftaroundabout

  • KTH Royal Institute of Technology
  • Stockholm
View GitHub Profile
@leftaroundabout
leftaroundabout / Enum.hs
Created April 1, 2012 23:22 — forked from depp/Enum.hs
Demonstration of how incorrect (Enum x, Enum y) => Enum (x, y) instance can be used for Enum a => Enum (a,a)
{-# LANGUAGE FlexibleInstances #-}
-- See http://stackoverflow.com/questions/9967790/instance-in-haskell
instance (Enum a) => Enum (a, a) 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)