List processing Flashcards
What is a list?
A list is a data structure consisting of a list of data elements that are of the same data type and size; the list is named by an identifier and the data elements stored can be integers, real numbers, characters or text strings.
What is a head?
this is the first element of the list.
What is a tail?
this is all the other elements of the list apart from the head
What is the length?
this is the number of elements in the list.
What is an Empty List?
A list with no elements is termed an empty list and is shown using the symbols [ ]
What is the haskell head?
In Haskell, a list can be written in the form of head : tail
Therefore, the list [6, 4, 9, 12] can be written as 6 : [4, 9, 12]
where 6 is the head of the list and [4, 9, 12] is the tail
What is the return head of the list?
Returns the first element of the list (1) using the head command in Haskell
Example:
head [1, 2, 3, 4, 5, 6]
1
What is the return tail of the list?
Returns the all the other elements apart from the head (2, 3, 4, 5, 6) using the tail command in Haskell
Example:
tail [1, 2, 3, 4, 5, 6]
[2, 3, 4, 5, 6]
What is the test for empty list?
Returns False if the list being checked is not empty using the null command in Haskell
Example:
null [ ]
True
Returns False if the list being checked is not empty using the null command in Haskell
Example:
null [1, 2, 3, 4, 5, 6]
False
What is the return length of list
Returns how many elements are contained in a list (6) using the length command in Haskell
Example:
length [1, 2, 3, 4, 5, 6]
6
What is constructing lists?
Assign an empty ( [ ] ) list using the let command in Haskell,
Example:
let emptylist = [ ]
emptylist
[ ]
Assign a list ( [5, 6, 7, 8] ) using the let command in Haskell, as shown in the example
Example:
let mylist = [5, 6, 7, 8]
mylist
[5, 6, 7, 8]
What is prepend an item to a list?
Add a new element [1] to the beginning of the list
[5, 6, 7, 8],
Example:
[5, 6, 7, 8]
let mylist = [1] ++ [5, 6, 7, 8]
mylist
[1, 5, 6, 7, 8]
What is append item to a list?
Add a new element [9] to the end of the list
Example:
[5, 6, 7, 8]
let mylist = [5, 6, 7, 8] ++ [9]
mylist
[5, 6, 7, 8, 9]