Programming Languages, Part A

https://www.coursera.org/learn/programming-languages

https://www.coursera.org/instructor/~873260

https://www.washington.edu/

Week 1: Intro with Standard ML. Personal note this language's syntax and simplicity reminds me of Kotlin.

Week 2: 
Variable bindings: ex. val z = (x+y) + (y+2); (* comment *)
Type-check expression and extend static env, evaluate expression and extent dynamic env.
Syntax: How you write something
Semantics: What that something means, ex. type-checking (pre-run), evaluation (during-run).

Every kind of expression has: Syntax, Type-checking rules: produces a type or fails, Evaluation rules (used on type checking): produces a value, exception, infinite loop.

Values: All values are expressions, not all expressions are values, every value evaluates to itself in zero steps.

Shadowing: Multiple variable bindings of the same variable is poor style & confusing.
val a = 1
val b = a (* b is bound to 1 *)
val a = 2

Function:
Is a value, evaluated later.
Type checking is for the result on the right.
Function calling has syntax, type checking,?.
Function evaluation has dynamic evaluation of func result, dynamic env eval of arg's values, result eval of func when args are mapped func env and all recursive funcs.

Tuples: fixed number of pieces that can have different types. Pair is a (2-tuple).
val x = (7, (true,9)) (* int * (bool&int) *)
val y = #1 (#2 x) (* bool *) not sure how this is bool, #2 x is x[2] where tuple vars start at 1
val z = (#2 x)

Lists: any number of values but must be same type.
Add to head via N::myList; (* pronounced cons, the operation can be repeated 4::5::6::myList*)
null myList (* is true if myList is empty [] *)
hd myList (* returns the head of the list, tl returns tail rest elements as a list aka !hd, both raise an exception if []*)
You can also recursively embed tl (tl n)
Create generic list via type 'a list

Let: syntax is let b1 in e end, this allows local scoped bindings. You can define functions in let scopes too.

Options: t option where t is type, similar to t list. Building NONE ('a option) or SOME (e of type t)
isSome has type 'a option -> bool
valOf has type 'a option -> 'a (exception if given NONE)

Boolean and Comparison Operations: a andalso b, a orelse b, not a. While the first two are keywords, not is not, it is a pre-def func. No shorthand syntax in ML. Standard int comparison syntax, but reals (like floats) are not ints and cannot be compared with ints, bust be type cast. <> can be used with any equality type but not with reals.

ML has a non-feature of no mutation, a feature of functional programming. Without mutation we don't care about aliasing or identical copies.

Pieces of a Language:

  1. Syntax: how to write language constructs?
  2. Semantics: what do programs mean; evaluation rules?
  3. Idioms: what are typical patterns for using language features to express computation?
  4. Libraries: what facilities does the language provide standard operations?
  5. Tools: what do language implementations provide to make job easier? (repl, debugger, code formatter).
Week 3:

Comments