module Mana where data Color = Colorless | Black | White | Red | Blue | Green deriving (Show, Eq) data Mana = Mana { amount :: Int , color :: Color } deriving (Show, Eq) data Cost = Cost [Mana] deriving (Eq) instance Show Cost where show c = pretty c class ManaCost a where converted :: a -> Int instance ManaCost Cost where converted (Cost []) = 0 converted (Cost cost) = (foldl (\t (Mana x _) -> t + x) 0) cost pretty :: Cost -> String pretty c = do let filtered c (Cost cost) = converted $ Cost $ filter (\x -> color x == c) cost let colored = concat [ replicate (filtered Black c) 'B' , replicate (filtered White c) 'W' , replicate (filtered Red c) 'R' , replicate (filtered Blue c) 'U' , replicate (filtered Green c) 'G' ] let colorless = filtered Colorless c if length colored > 0 && colorless == 0 then colored else (show colorless) ++ colored