1 of 31

Lecture 01

Welcome! Intro to OCaml

Programming Languages

UW CSE 341 - Winter 2021

2 of 31

Welcome! Stoked for this quarter 🥳

10 weeks to learn fundamentals of Programming Languages

  • Become better programmers, even in other languages
  • Learn to distinguish surface differences from deeper principles
  • Develop a systematic methodology for understanding what programs mean
  • Pick up some technical jargon to support further study

3 of 31

What is going to happen?

  • Bad course summary:
    • “Learn OCaml + Racket”
  • Better course summary:
    • Understand functional programming vs. object-oriented programming
    • Understand static types vs. dynamic types

4 of 31

Today

  1. Course mechanics
  2. Our first OCaml program

5 of 31

TODO

  • Read the course website
  • Make sure Zoom works
  • Sign in to Gradescope and the Discussion Board
  • Set up your programming environment for OCaml

6 of 31

About Me

  • PL research spanning diverse topics
    • Compilers, verification, floating point, 3D printing, ...
  • First-generation college student
    • Purdue (IN, BS 2007) → UCSD (CA, PhD 2014) → UW (WA, Prof 2013)
  • 8th year on the faculty, 6th time teaching 341
  • Running (slowly), reading, vegan cooking, meditation, …
    • Coming off a long Greg Egan binge, listening to Elder, exploring the Zettelkasten fad

7 of 31

8 of 31

2021 off to a

rough start 😭

9 of 31

But CSE 341 always brightens my day ☀️

2021 off to a

rough start 😭

10 of 31

TAs

  • Andres Paz
  • Kenny Wu
  • Michael Flanders
  • Jennifer Tao
  • Kevin Zhu

The Heroes

of CSE 341!

11 of 31

Course Creator

Dan Grossman

  • Eminent PL researcher
  • Vice Director of the Allen School
  • Highly successful Coursera PL course
  • Cornering the market on Internet Dad Jokes (@djg98115)

12 of 31

Course Creator

Dan Grossman

  • Eminent PL researcher
  • Vice Director of the Allen School
  • Highly successful Coursera PL course
  • Cornering the market on Internet Dad Jokes (@djg98115)

Recent Course Innovator

James Wilcox

  • Former UW PhD Student
  • Ported 341 to OCaml
  • Lots of great new ideas
  • Buckle up 😂

13 of 31

Staying in Touch

  • Discussion Board (Ed)
    • All asynchronous communication should go through Ed
    • Use “private threads” to communicate directly with staff
    • First time trying this out, hoping vibrant community emerges!
  • Lecture, Section, Office Hours
    • Show up, ask questions, hang out!
  • Please be patient, kind, and helpful 🤝

14 of 31

Lectures

  • Recordings: available to the class, but not public
  • Take notes! Preferably with pen and paper first 📝
  • Interaction is more fun for everybody!
    • Grand challenge figuring out how to make things click over Zoom
    • Need help from the whole class to the experience good for everyone
  • Let us know if you can’t make it to lecture

15 of 31

Section

  • Smaller group meetings, presents new material
    • Often needed to complete homework assignments
  • Will also be recorded, but also not public
  • Same attendance policy as lecture
    • Let us know if you can’t make it
  • Meets this Thursday
    • Get to know your TA!

16 of 31

Office Hours

  • Schedule and Zoom links on course website
  • Feel free to drop in just to chat!
    • Would love to meet everyone this quarter 👋

17 of 31

Remote Learning

  • Enormous uncontrolled experiment
    • Opportunity to try a bunch of new things!
    • Not planning on traditional exams, etc.
  • We are committed to figuring this out
    • Let us know how we can help make this a great 341
  • Your health and safety come first

18 of 31

Homework

  • Probably ~ seven-ish assignments
    • Mostly programming
    • Some PL “theory”
  • DO discuss with friends and classmates
  • DO NOT look at or share any code!

19 of 31

Homework

  • Start early! Some problems need sleep.
  • Two late days per assignment (strict)
    • No homework help on message board during late period
  • Challenge problems: for the fun of it
    • Poor effort-to-points tradeoff
    • Good effort-to-learning tradeoff
    • Don’t attempt challenges till everything else is done!

20 of 31

Academic Integrity

  • The rules are to help you learn
  • Most cheating arises from procrastination followed by panic
    • Much better to ask for an extension and more help instead!
    • If you do collaborate too closely, explicitly note that in your submission!
  • Don’t believe everything online
    • And please don’t post your solutions anywhere

21 of 31

Questions about mechanics?

22 of 31

Programming Languages

  • Fundamentals: design, implementation, theory, practice
  • View fundamentals through OCaml : and Racket ( )
    • Learn a lot from seeing the same idea in different guise
    • “Travel to see where you’re from.”
  • Focus on functional programming (FP)
    • Avoid mutation (assignment statements)
    • Functions are values

23 of 31

A Whole New World 🧞‍♂️

  • New language (OCaml)
  • New editor (VS Code, etc.)
  • New mode of exploring (REPL)
  • New for me too! (at least for teaching 341)
    • I have written my fair share of SML, OCaml, Haskell, Coq, etc. over the years though 👴
  • Let’s get set up and start learning the workflow
    • The sooner the better -- start early on Homework 01!

24 of 31

Mindset

25 of 31

Mindset

  • Let go” of everything you know
    • We’ll come back around to more mainstream friends like Java eventually!
  • Treat OCaml (“ML”) as some new alien game we’re learning to play 👽 🎲
    • We’ll describe OCaml systematically, then apply the same approach repeatedly
    • Lots of new concepts, but we’ll be able to compare and contrast language more rigorously
    • Trying to “translate everything into Java” will hold you back

26 of 31

Syntax + Semantics

  • Syntax: how programs are written down
    • Roughly “spelling and grammar”
  • Semantics: what programs mean
    • Type checking : compile time (aka “static”) semantics
    • Evaluation : run time (aka “dynamic”) semantics
  • Both syntax and semantics matter
    • 341’s view ≈ “Semantics give the essence of a PL. Syntax is more about taste.”

27 of 31

To the keyboard!

28 of 31

Defining Variable Binding

let x = e

Syntax:

  • Keyword: let
  • Variable: x
  • Expression: e
    • Many forms!
    • Defined recursively!

(* static env = ... *)

(* dynamic env = ... *)

let x = 34

(* static env = ...; x : int *)

(* dynamic env = ...; x -> 34 *)

29 of 31

Defining Variable Binding

let x = e

Semantics:

  • Type checking
    • Type check e : t (t is some type)
    • Add binding xt to static environment
  • Evaluation
    • Evaluate e to a value v
    • Add binding xv to dynamic environment

(* static env = ... *)

(* dynamic env = ... *)

let x = 34

(* static env = ...; x : int *)

(* dynamic env = ...; x -> 34 *)

30 of 31

ML Carefully So Far

  • A program is just a sequence of bindings
  • Typecheck each binding in order
    • Using static environment from previous bindings
  • Evaluate each binding in order
    • Using dynamic environment from previous bindings
  • So far, only variable bindings
    • More kinds of bindings coming soon!

31 of 31

For Next Time

  • Semantics of expressions
  • Make sure to get OCaml setup!
    • Guide posted on course website later today
    • Please help everyone out on the course discussion board