Lists Flashcards

1
Q

Define Lists

A

It stores elements of the same type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does let keyword do?

A

Helps to define a constant in GHCI environment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

show syntax of defining a list using let

A

let a = [1,2,3,4,5]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how to concatenate two lists together

A

using ++ operator. For example [1,2,3,4] ++ [4,5,6]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define ++ operator’s drawback

A

++ operator appends the second list to the end of the first. Due to lazy evaluation, Haskell will attempt to walk through every element in the first list. So if the first list is long, then the ++ operation will take a long time to complete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the cons operator

A

Symbol “:”. This adds an element of the list to the front. For example, ‘A’ : “ small cat” will produce “A small cat”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Advantage of cons operator

A

it is fast

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe [],[[]] and [[],[]]

A

First is an empty list. Second is a list which contains an empty list. Third is a list which contains two empty lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe !! operator

A

!! operator can be used to get an element at a particular index from a list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Give an example for !! operator

A

“Ramesh” !! 2 will return ‘m’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

From what value indeices in Haskell start 1 or 0?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can lists within a list be of different types

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Can lists within a list can be of different lengths

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what operators can be used to compare lists

A

, >=, ==, /=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In what order list comparison is done in Haskell

A

Lexicographic order. Left to right

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How two lists of different lengths are compared

A

comparison stops at the last element of the shortest list, in the worst case