Reputation: 683
could anyone explain the below algebric data type
data LOS = Cons Student LOS | Empty deriving (Show)
and
type Name = String
data Student = Student
{ firstName :: Name
, lastName :: Name
} deriving (Eq, Show)
I find it confusing the construction of the LOS data type
Upvotes: 1
Views: 98
Reputation: 5543
LOS
is defining a list of students. You either have an empty list (Empty
) or Cons
, which holds both a value or the rest of the list.
You can have a list with an element (Cons s1 Empty
), a list with two elements (Cons s1 (Cons s2 Empty)
) and so on.
Upvotes: 4