CS代写 COMP302: Programming Languages and Paradigms

COMP302: Programming Languages and Paradigms
Prof. (Sec 01) Francisco Ferreira (Sec 02)

School of Computer Science Mc

Copyright By PowCoder代写 加微信 powcoder

Week 6-1, Fall 2017

Functional Tidbit: Imperative vs Functional Programming!
“I find languages that support just one programming paradigm constraining.”
COMP302: Programming Languages and Paradigms 2 / 5

Warm-Up: Computation and Effects
Expressions in OCaml have characteristics:
• An expression has a type
• An expression evaluates to a value (or diverges).
Expressions in OCaml may also have an effect.
COMP302: Programming Languages and Paradigms 3 / 5

Warm-Up: Type, Values, and Effect
Given the following expression write down its type, its value (i.e. what the expression evaluates to), and its effect, if it has any.
COMP302: Programming Languages and Paradigms 4 / 5

Warm-Up: Type, Values, and Effect
Given the following expression write down its type, its value (i.e. what the expression evaluates to), and its effect, if it has any.
COMP302: Programming Languages and Paradigms 4 / 5

Warm-Up: Type, Values, and Effect
Given the following expression write down its type, its value (i.e. what the expression evaluates to), and its effect, if it has any.
• fun x -> x + 3 * 2
COMP302: Programming Languages and Paradigms 4 / 5

Warm-Up: Type, Values, and Effect
Given the following expression write down its type, its value (i.e. what the expression evaluates to), and its effect, if it has any.
• fun x -> x + 3 * 2
• ((fun x -> match x with [] -> true | y::ys -> false) , 3.2 *. 2.0)
COMP302: Programming Languages and Paradigms 4 / 5

Warm-Up: Type, Values, and Effect
Given the following expression write down its type, its value (i.e. what the expression evaluates to), and its effect, if it has any.
• fun x -> x + 3 * 2
• ((fun x -> match x with [] -> true | y::ys -> false) , 3.2 *. 2.0) • let x = ref 3 in x := !x + 2
COMP302: Programming Languages and Paradigms 4 / 5

Warm-Up: Type, Values, and Effect
Given the following expression write down its type, its value (i.e. what the expression evaluates to), and its effect, if it has any.
• fun x -> x + 3 * 2
• ((fun x -> match x with [] -> true | y::ys -> false) , 3.2 *. 2.0) • let x = ref 3 in x := !x + 2
• fun x -> x := 3
COMP302: Programming Languages and Paradigms 4 / 5

Warm-Up: Type, Values, and Effect
Given the following expression write down its type, its value (i.e. what the expression evaluates to), and its effect, if it has any.
• fun x • ((fun • let x • fun x • fun x
-> x + 3 * 2
x -> match x with [] -> true | y::ys -> false) , 3.2 *. 2.0)
= ref 3 in x := !x + 2
-> (x := 3; x)
COMP302: Programming Languages and Paradigms 4 / 5

Warm-Up: Type, Values, and Effect
Given the following expression write down its type, its value (i.e. what the expression evaluates to), and its effect, if it has any.
• fun x • ((fun • let x • fun x • fun x • fun x
-> x + 3 * 2
x -> match x with [] -> true | y::ys -> false) , 3.2 *. 2.0)
= ref 3 in x := !x + 2
-> (x := 3; x)
-> (x := 3; !x)
COMP302: Programming Languages and Paradigms 4 / 5

Today: Programming with State
• Mutable Data-Structures • Closures and Objects
COMP302: Programming Languages and Paradigms 5 / 5

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com