{-# OPTIONS_FRONTEND -F --pgmF=currypp #-} import Control.SetFunctions -- The implementation of coloring a map using a default rule -- (by Sergio Antoy). -- The states of the great north-west: data State = WA | OR | ID | BC deriving (Eq,Show) states :: [State] states = [WA, OR, ID, BC] -- Pair of states with a common border: adjacent :: [(State, State)] adjacent = [(WA,OR), (WA,ID), (WA,BC), (OR,ID), (ID,BC)] data Color = Red | Green | Blue deriving (Eq,Show) -- Some coloring for a state: color :: State -> (State, Color) color x = (x, Red ? Green ? Blue) -- Checks a coloring w.r.t. adjacent states: -- it is a failure if two states with the same color are adjacent: check :: [(State, Color)] -> [(State,State)] -> [(State,Color)] check (_ ++ [(s1,c)] ++ _ ++ [(s2,c)] ++ _) (_ ++ [(s1,s2)] ++ _) = failed check'default x _ = x main :: [(State, Color)] main = check (map color states) adjacent