Week7 Flashcards

(12 cards)

1
Q

what is functional programming

A

type of language that :
focus on what is to be computed not how to compute it

ie: we transform inputs into outputs without changing state or having side effects

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

Functional advantages

A

. Shorter programs ( made possible through lamba expressions and higher order functions like map , filter , reduce…)

. easier to understand

. easier to design than imperative

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

Functional disadvantages

A

.slower than imperative (remember immutability creates new copies per transformation -> more overhead and slower)

. less flexible -> immutability restricts flexibitlity we cant change state we must create a new copy ( remember val in scala )

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

What do we mean by evaluation

A

Evaluating is just simplifying an expression step-by-step until we reach a value or normal form that can’t be simplified any further.

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

Properties of evaluation

A

1) Unicity of normal form:
value uniquely dependent on components of expression and not dependent on the order of reduction

DONT GET CONFUSED THO I GOT CONFUSED AND I WILL ADDRESS BELOW :

If any reduction sequence terminates (i.e. reaches a normal form),
then all terminating sequences must reach the same result.

2) Non terminate :
Evaluation of an expression may not terminate ie doesnt have a value

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

Call by name

A

Reduce the function first using its definition, then evaluate the argument

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

call by value

A

Evaluate the argument first, then reduce the function using its definition

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

Call by name vs call by value

A

. Call by name will always find a value if there is one
. Call by value is more efficient but may not lead to a value (remember fourtytwo infinity function in slide)

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

What are the advantages and the disadvantages of the call-by-value strategy of evaluation
for functional languages?

A

Advatages:
more effiencnt as it removes redundant computational steps since argument evaluated first before applying function definition

easy to implement

disadvantages:
may lead to you not terminating and FAILING TO FIND A VALUE FOR A TERM EVEN IF IT HAS A NORMAL FORM

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

WHAT DOES HASKELL USE

A

Haskell uses lazy evaluation :
call by name + sharing

deferes evaluation of an expression until when its result needed for a computation

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

How does currying work and whats its type

A

Currying is the process of transforming a function that takes multiple arguments into a chain of functions, each taking one argument at a time.

curry :: ((a, b) -> c) -> a -> b -> c

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

uncurry

A

uncurry :: (a -> b -> c) -> (a, b) -> c

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