Lecture 001

Philosophy

Philosophy:

Imperative: execute command -> give effect Functional: evaluate function, has no effect

Parallelism Code

Parallelism Code

Span: running time if you have infinite processors (combine value takes time), longest critical path Type: a prediction about the kind of value an expression will have if it winds up reducing to a value Type Error: catch things before run-time (do type checking before evaluation) (ML compiler does that) Compound Type (connectives): build types from other types Value: most simplified form of an expression Well-typed (type-checks): if an expression has at least one type

Standard ML (SML): pure fragment (pure = effect-free) REPL: command line feedback in real time

Expression

ML Expression:

Reduction!

Reduction!

Well-formed ML expression e:

Int Type

Int Type

Typing Rule / Inference Rule

Typing Rule / Inference Rule

Evaluation Rule

Evaluation Rule

Well-typed expression may have no value: eg. 5/0, f(x) = f(x)+1

Extensional Equivalence

Extensional Equivalence
Expression equivalence:

Example:

Basic Types in ML

Basic Types: int, real, bool, char, string Constructed Types:

[1, 2, 3, 4] is a value [1+1 ,2, 3] is an expression

Type Example

Type Example

Type has:

Functions

Type of function: t1 -> t2 if t1, t2 are types

Totality: f is total if f(x) return a value for all value x in X. (for every argument)

Example Function

Example Function

Five Steps Methodology

Five Steps Methodology

Declaration

Declaration

Binding Examples

Binding Examples

The important lesson here is that function only know variables before the function is created. So if you have a variable in a function, and the variable is changed at a later time, the function will still use the variable as if it is unchanged. See below code: sml Standard ML of New Jersey (64-bit) v110.99 [built: Tue Feb 09 08:36:14 2021] val x = 1; (* val x = 1 : int *) fun add (a : int) : int = x + a; (* val add = fn : int -> int *) add 1; (* val it = 2 : int *) add 2; (* val it = 3 : int *) val x = 2; (* val x = 2 : int *) add 1; (* val it = 2 : int *) add 2; (* val it = 3 : int *)

Local Declaration

Local Declaration

Example of Scope

Example of Scope

Concrete Type Definition

Concrete Type Definition

Code Example

Code Example

Closures

Closures

Table of Content