CS 320: Principles of Programming
Languages
Introduction, Class Structure, Logistics, and Objectives
‘-
Marco Gaboardi
(Fall 2019)
and Assaf Kfoury
(Spring 2020)
What is your favorite language?
‘-
Why is it your favorite?
• Easy to program?
• Good debugging environment?
• Large amount of standard libraries?
• Syntax?
• Language you know the most?
• Performance (or other runtime characteristics)?
• Validation mechanisms (type checking, verification)? • Garbage collection?
‘-
PL
➢Formal mechanisms to reason about and specify programs / languages ‘-
• Type Systems, Verification
➢Compiler Design
• Optimizations, Program Analysis, JIT
➢Language Runtime Design
• Virtual Machines, Garbage Collection, JIT, Interpreters
What do we study in Programming Languages?
➢Language Design
• Programming Constructs, Abstractions
Why studying Programming Languages?
➢Learn how to learn
• Understanding the different design choices involved in the design of
a programming language will help you learn more easily different
programming languages.
‘-
think at a different level of abstraction.
➢Writing better code
• Understanding how your programs are transformed and executed by compilers and interpreters will help you design programs that are more reliable, secure and efficient.
➢Improve your programming skills
• Learning how a programming language is designed will help you to
What will we look at?
•We will study the functional programming paradigm
• We will study the different features and ‘-
constructs of programming languages,
• We will look at more formal ways to compare
different languages design choices,
• We will experiment with building our own language.
Topics Covered (tentative)
• Functional Programming
• Language Design and Evolution
• Syntax and Semantics
• Names, Bindings, and Scopes
• Data Types
• Expressions and Assignment Statements • Control Structures
• Subprograms and their Implementation
• Exceptions and Event Handling (tentative)
‘-
Piazza Etiquette
•Form questions in a general manner •Do not cut / paste your code
•Try to “distill” your question • ‘-
You can post anonymously
•Only teaching staff will know your identity
I have a question!
• •
subject line ‘- • Come to office hours
Ask on Piazza
If you send an email use [CS320] in the
Labs
•Attendance will be graded (participation) •30 Minutes of Presentation
•20 Minutes of Q/A
‘-
Programming Language we will use
‘-
www.ocaml.org
Assignment and Homework submissions
• Submission via Gradescope • More details to come
‘-
Questions?
‘-
Structure of classes
• Functional Programming in OCaml (first few weeks) • Concepts of Programming languages
‘-
What is a Functional Language
A functional language:
• defines programs in a way similar to the one we use
to define mathematical functions,
• avoids the use of mutable states (states that can
change) in describing what a program should do.
In a functional language, the information is maintained by the computation.
‘-
Thinking Functionally
In imperative languages like Java or C, you get most work done by changing the state of the memory, via variables or data structures
Commands modify or change the state – in this case an existing data s‘-tructure (pair)
In functional languages you get most work done by
temp = pair.x;
pair.x = pair.y;
pair.y = temp;
producing something new
let
(x,y) = pair
in (y,x)
Commands analyze an existing data (pair) and produce a new data (y,x)
Copyright David Walker
Why study functional programming?
1. Learning a different style of programming teach you that programming transcends programming in a language
2. Functional languages predict the future ‘-
3. Functional languages are more and more used in industry
4. Functional languages help writing correct code
Copyright Nate Foster
Learning a different style of programming teach you that programming transcends programming in a language
It is similar to human languages. • Speaking a language allows
‘-
one to communicate but in different situation one may need very different languages
• Learning another language helps understanding your native language better
Copyright Nate Foster
‘-
Copyright Nate Foster
Functional languages predict the future
• • •
•
•
Garbage collection Java [1995], LISP [1958] Generics Java 5 [2004], ML [1990]
Higher-order functions
‘-
C++11 [2011], Java 7 [2011] and ML [1990]
C#3.0 [2007], Java 8 [2014], LISP [1958]
Type inference
What’s next?
Copyright Nate Foster
Functional languages are more and more used in industry
‘-
Copyright Nate Foster
Functional languages help writing correct code
Abstraction:
Functional languages – mathematical functions Imperative languages – mutable state
Imperative languages
Machines are good at complex manipulations of states, humans are not good at reason about them.
Functional languages
Variable never change values and functions have no side-effect, this makes it easier to reason about them.
Copyright Nate Foster
‘-
‘-
A good functional language part of the ML family.
• • • • • •
Small core language,
Supports first-class higher order functions, Lexically scoped
Statically strongly typed
Type inference
It has a good community: ocalm.org
‘-
Copyright David Walker
Questions?
‘-