high order functions Flashcards

1
Q

what is a high order function

A

a function that takes a function as a parameter, returns a function or both

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

what are benefits of high order functions

A

allows flexible and reusable functions
allows you to encode common programming patterns(encapsulation)
enables function composition

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

function composition

A

combining functions for complex behaviours

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

what are some examples of high order functions

A

map
filter
foldr
all
any
(.)
takeWhile
dropWhile

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

map

A

applies a function to all values in a list

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

filter

A

selects every element that satisfies the function

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

all

A

returns all elements that satisfy the function

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

any

A

returns the first element that satisfies the function

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

(.)

A

returns the composition of two functions

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

takeWhile

A

takes elements from the start of the list that satsify the function/ predicate
stops when it gets to the first that doesnt

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

dropWhile

A

drops elements from the start of the list that satsify the function/ predicate
stops when it gets to the first that doesnt

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

foldr

A

recursive pattern
f[] = v
f(x:xs) = x # f xs
#: function

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

local bindings

A

variables or functions that are defined within a limited scope
usually inside a function

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

what can we use to do local bindings

A

where
let in

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

let in

A

let: defines the local bindings
in: the bindings are only available in this expression

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

where

A

introduces local bindings available for the entire function body

17
Q

foldr

A

recursively applies the given function to the list from right to left

18
Q

foldl

A

recursively applies the given function to the list from left to right

19
Q

list comprehension

A

constructs new lists from old lists

20
Q

what does list comprehension look like in haskell

A

[x^2 | x <- [1..5]]

21
Q

which part is the generator in list comprehension and why

A

x <- [1..5]]
states how to generate values for x

22
Q

dependant generator

A

when later generators depends on the variables introduced in the earlier generators

23
Q

what is the role of guards in list comprehension

A

the condition that limits the values that the generator can use

24
Q

zip

A

maps two lists to a list of pairs of their corresponding elements