Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
private string Do(ICell a, ICell b)
{
return a.Color + "\t-->\t" + b.Color;
}
?-- цвета (кто же рабоатет со строками)
data Color = Red | Blue | Green deriving (Show)
-- интерфес
class Colored a where
getColor :: a -> Color
--- проверка
process :: Colored a => a -> a -> String
process a b = process' (getColor a) (getColor b)
process' Red Red = "Red on Red"
process' Green Blue = "Coast"
process' a b = show a ++ " --> " ++ show b
data MyColor = MyRed | MyGreen | MyBlue deriving (Read)
-- имплементация интерфейса
instance Colored MyColor where
getColor MyRed = Red
getColor MyGreen = Green
getColor MyBlue = Blue
main = interact $ unlines . map ((\[a, b] -> process (read a::MyColor) (read b)) . words) . lines
(defclass icell () ()) (defclass red-cell (icell) ()) (defclass blue-cell (icell) ()) (defclass green-cell (icell) ()) (defgeneric colors (arg1 arg2) ) (defmethod colors ((a icell) (b icell)) (format nil "~S --> ~S" a b)) (defmethod colors ((a green-cell) (b blue-cell)) "побережье") (defmethod colors ((a red-cell) (b red-cell)) "красное на красном")
Двойная диспетчеризация