1/11
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
How do you write a list comprehension?
[x² | x ← [1..5]]
What does the symbol “|” mean?
“such that”, as in guard
What does the symbol “←” mean?
“drawn from”
What construction is “x ← [1..5]”?
A generator, which puts values into a function stated through a guard.
What does the function concat do?
Concatenates a list of lists into one list.
How do you write concat?
concat :: [[a]] → [a]
concat xss = [x | xs ← xss, x ← xs]
What does the function find do?
It finds an equality type value in a list of tuples.
How do you write the find function?
find :: Eq a => a → [(a,b)] → b
find k t = [v | (k’, v) ← t, k’==k]
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.
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]
What does a negative shift factor do in the Caesar cipher do?
It decodes the cipher!
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.