khaled alomar
khaled alomar

Reputation: 683

haskell : could anyone explain the below algebric data type

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

Answers (1)

mariosangiorgio
mariosangiorgio

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

Related Questions