-- This is an algebraic data type: data Pair = Pint Int Int | Pfloat Float Float deriving Show -- | -- >>> x -- Pint 6 7 x = Pint 6 7 -- | -- >>> y -- Pfloat 6.0 7.0 y = Pfloat 6.0 7.0 -- | -- >>> firstOfPair x -- 6 firstOfPair :: Pair -> Int firstOfPair (Pint x y) = x -- | -- >>> secondOfPair y -- 7.0 secondOfPair :: Pair -> Float secondOfPair p = case p of (Pfloat x y) -> y -- This is how the actual True and False are implemented: -- data Bool = True | False data MyBool = MyTrue | MyFalse deriving Show -- This is how the actual Maybe and nothing is implemented: -- data Maybe a = Nothing | Just a data MyMaybe a = MyNothing | MyJust a deriving Show -- Destructure (unwrap Just), built in: fromJust myFromJust :: MyMaybe a -> a myFromJust (MyJust a) = a -- | -- >>> myFromJust justThing -- 5 justThing = MyJust 5 -- This is how the (:) list operator works: data MyList a = Empty | MyCons a (MyList a) deriving (Show) emptyList = Empty oneBigList = MyCons 5 Empty threeBigList = MyCons 3 (MyCons 4 (MyCons 5 Empty)) -- | -- >>> listSugar == listNoSugar -- True listEmpty = [] listSugar = [1,2,3] listNoSugar = 1 : (2 : (3 : []))