module Set where import Pai import Data.List (sort) import Data.Char (isDigit) import Data.Either data MSet = MSet {getMSet:: [MCard]} instance Show MSet where show xs = fst $ foldr f ("",Nothing) $ sort $ getMSet xs where f (MCard col n) (o,p) = let o' = show n ++ (if Just col == p then "" else show col) ++ o in (o', Just col) readMSet r = fst $ foldr f ([],Man) $ map g r where g x | isDigit x = Left ((read [x])::Int) | otherwise = Right ((read [x])::MCol) f (Left a) (xs,col) = ((MCard col a):xs,col) f (Right a) (xs,col) = (xs,a)