1 of 29

Lecture 01

Welcome!

Course Logistics; Variables in OCaml

Programming Languages

UW CSE 341 - Winter 2022

2 of 29

Welcome!

10 weeks to learn some fundamental concepts of Programming Languages

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

3 of 29

What is going to happen?

  • Bad course summary:
    • “Learn OCaml + Racket”
  • Better course summary:
    • Distinguish functional programming vs. object-oriented programming and use both effectively
    • Understand static types vs. dynamic types
    • Reason precisely about scope in many software settings
    • ...

4 of 29

Today

  1. Course mechanics
  2. Our first OCaml program

5 of 29

TODO

  • Read the course website especially the syllabus
  • Sign in to the Discussion Board
    • Must receive Discussion Board announcements, which also get emailed to you
  • Set up your programming environment for OCaml
  • Do “Homework 0” (simple survey, due Friday, 5pm)

6 of 29

About Me: Dan-or-whatever :-) (he/him)

  • Allen School faculty since 2003, CSE 341 is my favorite class
    • This is my 14th time teaching it :-O
  • Have also taught 331, 332, 351, 480, ... (I taught 142 once…)
  • Also: Research, Allen School Vice Director, made a 341 MOOC in 2013, ...
  • I do hope we’ll mostly be in-person, but I taught 341 in Spring 2021, so I can Zoom-from-my-basement-as-needed

7 of 29

So, Winter 2022…

  • Stay safe!
  • Whatever COVID throws at us, we’ll make it work: 341 will be great!
  • I hope most of the quarter is in person
    • We will follow all masking rules, etc.
    • You will gain much more from attending in-person regularly
    • But don’t come up if you’re sick
  • Zoom logistics: I have chat open on a second laptop, voicing questions after raise-hand also encouraged

8 of 29

You know…

The pandemic is awful for all of us in many different ways…

… being able to execute a great course that I hope forever changes your view of software is something I can do “despite it all”

9 of 29

Staying in Touch

  • Asynchronous communication can go through Ed
    • Use “private threads” to communicate directly with staff
  • Lecture, Section, Office Hours
    • Show up, ask questions, hang out!
  • Anonymous feedback link on course homepage
  • Please be patient, kind, and helpful 🤝

10 of 29

Lectures

  • Take notes! Preferably with pen and paper first 📝
  • Interaction is more fun and useful for everybody!
  • Lecture will be recorded
    • Available only to class members

11 of 29

Section

  • Smaller group meetings, presents new material
    • Often needed to complete homework assignments
  • Will not be recorded (over Zoom we might record one?)
    • But we will share materials
  • Get to know your TAs!

12 of 29

Office Hours

  • Schedule on course website in next day or so
    • Some in person, some on Zoom
  • Feel free to drop in just to chat!
    • Would love to meet everyone this quarter 👋
    • Ideally not just for homework questions (but those are good too)

13 of 29

Homework

  • Probably 7 total, mostly programming
  • DO discuss with friends and classmates
  • DO NOT look at or share any code!
  • In other words, “individual assignments”

14 of 29

Academic Integrity

  • The rules are to help you learn and be fair to all
  • Most cheating arises from procrastination followed by panic
    • Much better to reach out to the course staff; let us help you
    • If you do collaborate too closely, explicitly note that in your submission!
  • Don’t believe everything online; the homework is not web-search
    • And don’t post your solutions anywhere

15 of 29

Homework Strategy

Doing the homework involves:

  1. Understanding the concepts being addressed
  2. Writing code demonstrating understanding of the concepts
  3. Testing your code to ensure you understand and have correct programs
  4. “Playing around” with variations, incorrect answers, etc.

We only grade (2), but focusing only on (2) makes the homework harder (!)

16 of 29

Homework Logistics

  • Start early! Some problems may need sleep
  • Questions tend to be very precise and concise
  • Two late days per assignment (strict)
    • No staff help on message board during late period
  • Challenge problems: for the fun and interest of it
    • Poor effort-to-points tradeoff
    • Good effort-to-learning tradeoff
    • Don’t attempt challenges until the rest is done

17 of 29

Exams

  • We won’t deprive you of the opportunity to review and learn in ways that coding assignments don’t get at
    • Seriously!
  • But need some flexibility this quarter [pandemic]
    • Midterm will be take-home, open course-website, open compiler, 2 hours within a 1-2 day interval, etc.
    • Hope to have final in-person in regularly scheduled slot

18 of 29

Questions about mechanics?

19 of 29

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

20 of 29

A Whole New World

  • New language (OCaml)
  • New editor (VS Code, etc.)
    • Not my usual editor :-)
  • New mode of exploring (REPL)
  • Let’s get set up and start learning the workflow
    • Sooner the better -- do not delay fighting installation demons

21 of 29

Mindset

22 of 29

Mindset

  • Let go” of everything you know
    • We’ll come back around to mainstream friends (Java) eventually!
  • Treat OCaml (“ML”) as a 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 languages more rigorously
    • Trying to “translate everything into Java” will hold you back
  • I will motivate the entire course… a few weeks from now
    • Once we have shared vocabulary

23 of 29

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.”

24 of 29

To the keyboard!

25 of 29

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 *)

26 of 29

Defining Variable Binding

let x = e

Semantics:

  • Type checking
    • Type check e with some type t
    • Add binding xt to the static environment
  • Evaluation
    • Evaluate e to some value v
    • Add binding xv to the dynamic environment

(* static env = ... *)

(* dynamic env = ... *)

let x = 34

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

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

27 of 29

Defining Variable Binding

let x = e

Semantics:

  • Type checking
    • Type check e with some type t
    • Add binding x : t to the static environment
  • Evaluation
    • Evaluate e to some value v
    • Add binding xv to the dynamic environment

metavariables in blue

(* static env = ... *)

(* dynamic env = ... *)

let x = 34

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

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

28 of 29

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!

29 of 29

Coming up

  • Semantics of expressions
  • Make sure to get OCaml setup!
  • Do “Homework 0” (simple survey)