Summentyp in Haskell
data Shape = Circle {center::Point, radius::Double}
| Square {anchor::Point, length::Double}
Das deklariert und definiert einen Summentyp. Dabei wird der Typ Shape, alle Konstruktorfunktionen und die Selektoren automatisch erzeugt:
Shape -- Typ
Circle :: Point -> Double -> Shape -- Konstruktor
Square :: Point -> Double -> Shape -- Konstruktor
center :: Shape -> Point -- Selektor
radius :: Shape -> Double -- Selektor
anchor :: Shape -> Point -- Selektor
length :: Shape -> Double -- Selektor