конструкторов
data WeekDay = Sun | Mon | Tue | Wed | Thu | Fri | Sat
data Bool = False | True
Использование конструкторов
weekend :: WeekDay -> Bool
weekend Sun = True
weekend Sat = True
weekend _ = False
Конструкторы с параметром
data Coord = Point Double Double
data Pair a = Couple a a
Использование конструкторов с параметрами
distance :: Coord -> Coord -> Double
distance (Point x1 y1) (Point x2 y2) =
sqrt ((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1))
swap :: Pair a -> Pair a
swap (Couple x y) = Couple y x
data Coord = Coord Double Double
data Pair a = Pair a a
distance :: Coord -> Coord -> Double
distance (Coord x1 y1) (Coord x2 y2) =
sqrt ((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1))
swap :: Pair a -> Pair a
swap (Pair x y) = Pair y x