Section 1

Preview this deck

How to repeatedly display a list?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

7 years ago

Date created

Mar 1, 2020

Cards (61)

Section 1

(50 cards)

How to repeatedly display a list?

Front

(cycle [list]) WARNING without a stopping point this is an infinite loop so you could do "take 10 (cycle [1,2,3])"

Back

Prefix Math

Front

div - whole number division (div 8 7) mod - remainder of int division (mod 8 7) abs - absolute value (abs (-7)) negate - change sign of int (negate 7)

Back

How to reverse a list?

Front

reverse [list]

Back

How to make a function doubleUs?

Front

editor filename z y = z x 2 + y x 2

Back

How to make a function doubleSmallNumber using if and then?

Front

doubleSmallNumber x = if x>100 then x else x*2

Back

How to make a the function doubleMe?

Front

editor filename doubleMe x = x+x

Back

How to create a list of lists of numbers named "numbers"? (A lists with lists in them)

Front

numbers :: [[Int]] numbers = [ [ 1,4,7 ] , [ 2,5,8 ] , [ 3,6,9] ],

Back

How to define a list type?

Front

listName :: [Type]

Back

How to find lowest number in a list?

Front

minimum [list]

Back

can you zip two types of lists?

Front

Yes this makes them ordered pairs or tuples

Back

Prefix Boolean

Front

not(bool) (not(true)==false)

Back

Create the same list, two different ways with the values 1,2,3,4

Front

list = [1,2,3,4] list = 1:2:3:4:[ ] (needs to be {values :list}

Back

How to grab a number of elements from the front of a list?

Front

take # [list]

Back

How do you use shell commands while in haskell?

Front

:! [command]

Back

How to find highest number in a list?

Front

maximum [list]

Back

How to create a range that goes by 2, up to 50?

Front

numRangeName :: [Int] numRangeName = [2,4..50]

Back

How to check if a list if empty?

Front

null [list]

Back

How to use init command?

Front

init displays all except last element and the command is init [list]

Back

How to use a function in a function using doubleMe and doubleUs?

Front

editor filename doubleUs x y = doubleMe x + doubleMe y (function have high priority on PEMDAS)

Back

How does comparison work?

Front

compares the first element only unless equal, then it compares the next and if equal compares the next and so on...

Back

Describe basic structure for set builder notation

Front

[expression | values, conditions]

Back

How to get rid of elements from a list?

Front

drop # [list]

Back

How to index in a list?

Front

[list] !! { # } (starts at 0)

Back

How to use the head command?

Front

head displays first element and command is head [list]

Back

How to reload the program?

Front

:reload or :r

Back

What does read do? Also display command

Front

Reads in a string and another value and tries to perform an operation (ex. read "3.4" + 4.0 = 7.4 or read "True" || false = True)

Back

How to make a list of pancake toppings with defined type?

Front

pancakes :: [String] ([[Char]] will work as well) pancakes = ["Chocolate","Banana","Strawberry","Blueberry"]

Back

How to search through commands?

Front

:tab [letter] (the letter can be used to limit search to commands starting with letter)

Back

How to find the product of a list?

Front

product [list]

Back

How to check if an element in a list?

Front

ex. 4 `elem` [3,4,5,6] is true ex. 4 `elem` [3,5,6] is false

Back

Create two functions: Create "Square" that squares input with values 1-10 Create "Cube" that cubes input with values 1-10 and the cubed number is higher than 20

Front

square = [ x*x | x <- [1..10] ] cube = [ x^3 | x <- [1..10], x^3 > 20 ]

Back

How to add two lists together?

Front

list1 ++ list2

Back

Create a function: -outputs "Go!" if Odd -outputs "Pack!" if Even -outputs "Cheeseheads!" otherwise

Front

packers xs = [if x `mod` 2 == 0 && x /=0 then "Go!" else if x `mod` 2 == 1 then "Pack!" else "Cheeseheads!" | x<-xs ]

Back

How to create a list 1-50? and another A-Z?

Front

numRangeName :: [Int] numRangeName = [1..50] ~~~~~~~~~~~~~~~~~~~~~~~~ letRangeName :: [Char] letRangeName = ['A'..'Z']

Back

General Structure of a function call

Front

[function name] [formal parameters] = [result]

Back

Infix Math

Front

+ sum of 2 ints (2 + 3) - difference of 2 ints (2 - 3) x the product of 2 ints (3 * 2) ^ raise a base to a power (2^3)

Back

How to get a length of the list?

Front

length [list]

Back

how to zip two lists?

Front

list1 `zip` list2

Back

How to use tail command?

Front

tail displays all except head and command is tail [list]

Back

How to open up editor?

Front

editor filename extension

Back

How do you use prefix functions as infix?

Front

backticks ( 8 `div` 4)

Back

How to open up Haskell in terminal?

Front

ghci

Back

How to find the sum of a list?

Front

sum [list]

Back

Infix Boolean

Front

&& - and (True && True) || - or (True || False)

Back

How to use last command?

Front

last displays the last element in the list and command is last [list]

Back

Create a function that removes all lowercase letters from a word

Front

removeLower word = [ letter | letter <-word, letter `elem` [ 'A'..'Z']]

Back

How to clear the screen?

Front

:! clear

Back

Single line comment

Front

--

Back

How to load a file into haskell?

Front

:l filename

Back

How to tell what type a value is?

Front

:type <value> or :t

Back

Section 2

(11 cards)

Templates

Front

definition: pattern = result Guard: [SPACE] |expression = result [SPACE] | otherwise = result Where: result where pattern = result Let: Pattern = result in result Case: expression of pattern = result

Back

Create a function fib that gives the Fibonacci number for an index input

Front

fib :: Int->Int fib index [space] index <= 1 = 0 [space] index == 1 = 1 [space] otherwise = (fib (index - 1)) + (fib (index - 2))

Back

Example of a composition function

Front

(not . not) True

Back

What does show do? Also display command

Front

shows the output as a string

Back

Example of a partially applied function

Front

doubleAll:: [Int] → [Int] doubleAll = map (Multiply 2)

Back

Create a function reverse prime using pattern matching and recursion

Front

reverse' :: [a] -> [a] reverse' [] = [] reverse' (elem1:list) = reverse' list ++ [elem1]

Back

Use filter to create a high order function

Front

Filter isEven [list] (where isEven::Integer -> Bool)

Back

How to force the read command wtih 1 input?

Front

read value :: type (ex. read "4" :: Int)

Back

Create a function max prime using guards

Front

max' :: (Ord a) => a -> a-> a max' a b [space] | a > b = a [space] | otherwise = b

Back

Implement double in doubleAll with integers

Front

double x = x^2 doubleAll::[Integer] -> [Integer] doubleAll list = map double list

Back

Example of a applied function

Front

not $ not $ True or not $ not True

Back