Week7 ACTUAL Flashcards

(14 cards)

1
Q

What is functional programs and what does it consist of

A

program that consists of functions and focuses on what is to be computed not how it is computed

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

What is a function

A

mapping from set A to set B where A is domain and B is codomain

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

Advantages of function programs

A

.shorter programs
.easier to understand
.easier to design

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

Disadvantage

A

.Slower than imperative
. Less Flexible

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

Evaluation

A

Sequence of simplifying an expression (through reduction steps) until a value is obtained that cant be simplified further

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

Properties of evaluation

A

Unicity :
Value uniquely determined by components of expression and independent of the order of reduction

(ie all terminating reduction sequences must have the same value)

Non terminating:
Not all reduction sequences have a value , some may fail to terminate

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

What are the 2 main strategies of evaluation and explain them

A

Call by name:
reduce the function using its definition before evaluating its arguments

Call by value:
Evaluate arguments before reducing the function using its definition

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

Lazy evaluation

A

Haskell’s lazy evaluation is an implementation
of a call by name strategy, where arguments are evaluated if needed, using sharing to avoid
duplicating computations

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

Compare Call by name and call by value

A

. Call by name -> guaranteed to find a value if there is one
. call by value -> more effient but may fail to find a value even if there is one

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

Advantages of call by value

A

Advantages:
Since we evaluate arguments first (before reducing the function according to its defintion) no redundant computational steps [ ONLY MORE EFFICIENT IF ARGUMENT IS USED MORE THAN ONCE OTHERWISE EFFICIENCY IS THE SAME]

. easy to implement

Disadvantages:
may fail to find a value ( lead to you not terminating) even if there is a normal form associated to expression

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

What does Haskell use

A

Haskell uses lazy evaluation
lazy evaluation = call by name + sharing

It defers evaluating arguments until results are needed for computation

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

What is currying

A

When applying a function with more than 1 argument yields another function with n -1 arguments
This allows the creation of new functions via partial functions

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

Curry type

A

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

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

uncurry

A

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

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