Keywords

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

12 Terms

1
New cards

How do you write a list comprehension?

[x² | x ← [1..5]]

2
New cards

What does the symbol “|” mean?

“such that”, as in guard

3
New cards

What does the symbol “←” mean?

“drawn from”

4
New cards

What construction is “x ← [1..5]”?

A generator, which puts values into a function stated through a guard.

5
New cards

What does the function concat do?

Concatenates a list of lists into one list.

6
New cards

How do you write concat?

concat :: [[a]] → [a]
concat xss = [x | xs ← xss, x ← xs]

7
New cards

What does the function find do?

It finds an equality type value in a list of tuples.

8
New cards

How do you write the find function?

find :: Eq a => a → [(a,b)] → b
find k t = [v | (k’, v) ← t, k’==k]

9
New cards

What does the zip function do?

It takes a list, or multiple lists, and pairs elements based on their index into tuples. So it either pairs successive elements in the same list, or the first elements in two, the second elements in that two, and so on.

10
New cards

What is the Caesar cipher Haskell program?

import Data.Char

let2int :: Char → Int
let2int c = ord c - ord ‘a’

int2let :: Int → Char
int2let n = chr(ord ‘a’ + n)

shift :: Int → Char → Char
shift n c | isLower c = int2let((let2int c +n) ‘mod’ 26)
| otherwise = c

encode :: Int → String → String
encode n xs = [shift n x | x ← xs]

11
New cards

What does a negative shift factor do in the Caesar cipher do?

It decodes the cipher!

12
New cards

What is ord?

A function from the Data.Char module that converts a character into its corresponding Unicode integer value, where ord ‘a’ = 97.
So let2int c = ord c - ord ‘a’ is actually taking away 97 from the unicode integer value of any character as to put it between 0 and 25.