Skip to content

Instantly share code, notes, and snippets.

Justus Sagemüller leftaroundabout

  • Høgskulen på Vestlandet
  • Bergen
View GitHub Profile
@leftaroundabout
leftaroundabout / Enum.hs
Created Apr 1, 2012 — 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)
View Enum.hs
{-# 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)
You can’t perform that action at this time.