Answers
- Lists can be created with the syntax
[e1,...,en]
wheree1
,...,en
is a comma-separated list of elements. The empty list is just written[]
. More primitive notation for constructing a composite list is(e:es)
, wheree
is the first element of the new list andes
is an existing list that becomes the tail (or remainder) of the new list.Lists can be processed with a range of predefined list functions, with list comprehensions and with custom functions (see the next question).
- Functions over lists can be defined by pattern matching, just like for other ADTs. The typical form distinguishes two cases, that of the empty list
[]
and of the non-empty list(x:xs)
. - ADT definitions are recursive when we mention the type we are defining in one or more of its constructors field types. They are processed, like ordinary ADTs, with pattern matching on the constructors. Usually the functions are recursive and make use of structural recursion (see the next question).
- In structural...