CSE 130 [Spring 2014] Programming Languages

Similar documents
Programming Languages. So why study PL? A Programming Language. A different language is a different vision of life. CSE 130 : Spring 2015

Programming Languages. So why study PL? A Programming Language. A different language is a different vision of life. CSE 130 : Fall 2015

A Programming Language. A different language g is a different vision of life. CSE 130 : Fall Two variables. L1: x++; y--; (y=0)?

A Programming Language. A different language g is a different vision of life. CSE 130 : Spring Two variables. L1: x++; y--; (y=0)?

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE 130 : Fall 2013

Programming Languages

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE 130 : Fall 2014

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE : Fall 2017

So what does studying PL buy me?

Programming Languages

Any questions. Say hello to OCaml. Say hello to OCaml. Why readability matters. History, Variants. Plan (next 4 weeks)

Plan (next 4 weeks) 1. Fast forward. 2. Rewind. 3. Slow motion. Rapid introduction to what s in OCaml. Go over the pieces individually

OCaml. History, Variants. ML s holy trinity. Interacting with ML. Base type: Integers. Base type: Strings. *Notes from Sorin Lerner at UCSD*

Programming Languages

Programming Languages

News. Programming Languages. Complex types: Lists. Recap: ML s Holy Trinity. CSE 130: Spring 2012

OCaml. ML Flow. Complex types: Lists. Complex types: Lists. The PL for the discerning hacker. All elements must have same type.

Programming Languages

Programming Languages

Programming Languages

Programming Languages

CMSC 330: Organization of Programming Languages. Functional Programming with Lists

Begin at the beginning

Lists. Prof. Clarkson Fall Today s music: "Blank Space" by Taylor Swift

Side note: Tail Recursion. Begin at the beginning. Side note: Tail Recursion. Base Types. Base Type: int. Base Type: int

CMSC 330: Organization of Programming Languages. Functional Programming with Lists

Tail Recursion: Factorial. Begin at the beginning. How does it execute? Tail recursion. Tail recursive factorial. Tail recursive factorial

Recap from last time. Programming Languages. CSE 130 : Fall Lecture 3: Data Types. Put it together: a filter function

CSE 130 [Winter 2014] Programming Languages

Course outline. CSE 341: Programming Languages. Why study programming languages? Course motivation and objectives. 1 lecture: Concepts

Welcome to CS 135 (Winter 2018)

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

Lecture 1. Course Overview, Python Basics

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

CS457/557 Functional Languages

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

Lecture 1. Course Overview, Python Basics

Functional Programming

Introduction to Nate Foster Spring 2018

Programming Languages and Techniques (CIS120)

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

CSE 341: Programming Languages

Which of the following expressions has the type int list?

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

Welcome to CS 135 (Fall 2018) Themes of the course. Lectures. cs135/

Recap: ML s Holy Trinity. Story So Far... CSE 130 Programming Languages. Datatypes. A function is a value! Next: functions, but remember.

CSE 130 Programming Languages. Lecture 3: Datatypes. Ranjit Jhala UC San Diego

CSE 130 Programming Languages. Datatypes. Ranjit Jhala UC San Diego

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont.

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

CSE 341: Programming Languages

News. Programming Languages. Recap. Recap: Environments. Functions. of functions: Closures. CSE 130 : Fall Lecture 5: Functions and Datatypes

WELCOME TO CSE 100! Advanced Data Structures in C++

CSCI-GA Scripting Languages

Announcements. 1. Forms to return today after class:

Background. CMSC 330: Organization of Programming Languages. Useful Information on OCaml language. Dialects of ML. ML (Meta Language) Standard ML

Programming Languages

WELCOME TO CS 16! Problem Solving with Computers-I.

CS 241 Data Organization. August 21, 2018

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

COSE212: Programming Languages. Lecture 0 Course Overview

CSE 130 : Fall Programming Languages. Lecture 11: Ranjit Jhala UC San Diego. programming

EECE.2160: ECE Application Programming Spring 2017

Programming Languages

Intro. Scheme Basics. scm> 5 5. scm>

CS 3110 Lecture 1 Course Overview

CS 106B, Lecture 1 Introduction to C++

CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists. Dan Grossman Fall 2011

CSc 2310 Principles of Programming (Java) Jyoti Islam

CS 6371: Advanced Programming Languages

Monday Feb 16, 5pm. solve these equalities. Midterm Thursday Feb 12. covers only ocaml part of the course, assignments 1 through 3.

Programming Languages and Techniques (CIS120)

CSE 130: Programming Languages. Polymorphism. Ranjit Jhala UC San Diego

Distributed Systems Intro and Course Overview

Introduction to OCaml

Function definitions. CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists. Example, extended. Some gotchas. Zach Tatlock Winter 2018

CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists. Zach Tatlock Winter 2018

On Academic Dishonesty. Declarative Computation Model. Single assignment store. Single assignment store (2) Single assignment store (3)

WELCOME TO CS 16! Enrollment status: 117/ Problem Solving with Computers-I

Introduction to: Computers & Programming: Review prior to 1 st Midterm

CS 11 Haskell track: lecture 1

CS1 Lecture 3 Jan. 22, 2018

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Welcome to CS61A! Last modified: Thu Jan 23 03:58: CS61A: Lecture #1 1

ECE573 Introduction to Compilers & Translators

CS 1110, LAB 1: PYTHON EXPRESSIONS.

The Environment Model. Nate Foster Spring 2018

Introduction to Data Management CSE 344. Lecture 1: Introduction

02157 Functional Programming. Michael R. Ha. Lecture 1: Introduction and Getting Started. Michael R. Hansen

COS 326 Func,onal Programming: An elegant weapon for the modern age David Walker Princeton University

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

Example Scheme Function: equal

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

Introduction, Functions

CIS192: Python Programming

by the evening of Tuesday, Feb 6

Transcription:

CSE 130 [Spring 2014] Programming Languages Course Introduction! Ravi Chugh! Filling in today for Ranjit Jhala Apr 01

A Programming Language Two variables x, y Three operations x++ x-- L1: x++; y--; L2:! (y=0)?l2:l1 (x=0)? L1:L2;! Fact: This is equivalent to to every PL!! Good luck writing quicksort or Windows, Google, Spotify!!

So Why Study PL? A different language is a different vision of life - Federico Fellini!

So Why Study PL? Programming Language Shapes Programming Thought!

So Why Study PL? Programming Language Affects How: Shapes Ideas are expressed Programming Thought! Computation is expressed!

Course Goals Free your mind - Morpheus!

Learn New Languages / Constructs New ways to: - describe - organize - think about computation!

Write Programs That Are: Readable Correct Extendable Modifiable Reusable!

To Learn!

Learn How to Learn New PLs No Java, C# 20 years ago AJAX? Python? Ruby? Erlang? F#?... Learn the anatomy of a PL Fundamental building blocks Different guises in different PLs Re-learn the PLs you already know!

To Design New Languages!

Learn How to Design New PLs Who, me? Buried in every extensible system is a PL Emacs : Lisp Word, Powerpoint : Macros, VBScript Unreal : UnrealScript (Game Scripting) Facebook : FBML, FBJS SQL, Renderman, LaTeX, XML!

Choose Right Language!

Learn How to Choose Right PL But isn t that decided by libraries, standards, and my boss? Yes! My goal: educate tomorrow s tech leaders & bosses, so you ll make informed choices!

Speaking of Right and Wrong...!

Imperative Programming!

x = x+1

x = x+1

Imperative = Mutation!

Imperative = Mutation!

Don t Take My Word For It John Carmack Creator of FPS: Doom, Quake,...!

Don t Take My Word For It Tim Sweeney (Epic, Creator of UNREAL)! In a concurrent world, imperative is the wrong default!

Functional Programming!

Func%onal Functional Programming? No Assignment. No Muta0on. No Loops.!

Functional Programming OMG! Who uses FP?!?!

So, So, Who Uses FP?? MapReduce!

So, So, Who Uses FP?? Linq, F#!

So, So, Who Uses FP?? Erlang!

So, So, Who Uses FP?? Scala!

So, So, Who Uses FP?? OCaml!

So, So, Who Uses FP?? CSE 130!

Course Staff Instructor! TAs! Tutors! Patrick Torbett! Ranjit Jhala! Eric Seidel! Derek Huynh! Lucas Cycon! Office Hours TBD, Check Website! Daniel Ricketts!

Course Website cseweb.ucsd.edu/classes/sp14/cse130-a/! Nothing printed, everything on the web Feel free to bring a laptop to class!

Discussion Board Piazza will be used for all questions, announcements, clarifications, etc. Check often! If you haven t received a request to join, email jhala@cs.ucsd.edu!

Discussion Sections Wednesdays 5:00pm to 5:50pm 6:00pm to 6:50pm SOLIS 104 (same as lecture)! Starts Tomorrow!

Clickers + Peer Instruction (ish) Quick Poll: How many people do not already have an i>clicker?

Clickers + Peer Instruction (ish) Make class interactive Help YOU and ME understand what s tricky Everyone must bring an i>clicker to class by Tues 4/8 (we ll practice until then) available at bookstore Seating in assigned groups Check course webpage!

In-Class Clicker Exercises 1. Solo Vote : Think for yourself, then vote 2. Group Discussion : Groups of ~3 students Practice analyzing, talking about tricky notions (Try to) reach consensus If you have questions, raise your hand! 3. Group Vote : Everyone in group votes 4. Class Discussion : What did you find easy/hard? Questions from here show up in exams

In-Class Clicker Exercises Participation counts for 5% of your grade Respond to 75% of the questions throughout the quarter So, don t fret if you miss a class or two Register your clicker! (check webpage)

Grading and Exams No Official Before-Class Homework In-Class Exercises: 5% Programming Assignments (6-8): 30% Midterm: 30% Final: 35%

Programming Assignments Schedule up on webpage Usually due on Mondays or Fridays at 5:00 PM You may use up to four late days total Each late day is a single or whole unit 5 mins late = 1 late day Plan ahead, no other extensions!

No Textbook Online lecture notes Resources posted on webpage Pay attention to lecture and section! Do assignments yourself!!

Plan for Next 10 Weeks 1. FP, OCaml, ~5 weeks 2. OO, Scala, ~4 weeks 3. Logic, Prolog, ~1 week

Programming Assignments + Unfamiliar languages + Unfamiliar environments! Start Early!!

Programming Assignments No Compile, No Score!

Programming Assignments Forget Java, C, C++, other 20 th century PLs! Don t complain that OCaml is hard that OCaml is @!%@#! Immerse yourself in new languages!

Free! your! mind.!

Word From Our Sponsors Programming Assignments done ALONE We use plagiarism detection software Have code from all previous classes MOSS is fantastic, plagiarize at your own risk

Word From Our Sponsors Programming Assignments done ALONE We use plagiarism detection software Have code from all previous classes MOSS is fantastic, plagiarize at your own risk Zero Tolerance offenders punished ruthlessly Please see academic integrity statement Click Fraud is also not allowed!!

To Ask Me Questions!

Say Hello to OCaml void sort(int arr[], int beg, int end){ if (end > beg + 1){ int piv = arr[beg]; int l = beg + 1; int r = end; while (l!= r-1){ if(arr[l] <= piv) l++; else swap(&arr[l], &arr[r--]); } if(arr[l]<=piv && arr[r]<=piv) l=r+1; else if(arr[l]<=piv && arr[r]>piv) {l++; r--;} else if (arr[l]>piv && arr[r]<=piv) swap(&arr[l++], &arr[r--]); else r=l-1; swap(&arr[r--], &arr[beg]); sort(arr, beg, r); sort(arr, l, end); } } Quicksort in C! let rec sort xs = match xs with [] -> [] h::t -> let (l,r) = List.partition ((<=) h) t in (sort l) @ h::(sort r) Quicksort in OCaml!

Say Hello to OCaml Readability matters! sort=:(($:@(<#[),(=#[),$:@(>#[))({~?@#))^: (1:<#) Quicksort in J!

Say Hello to OCaml let rec sort xs = match xs with [] -> [] h::t -> let (l,r) = List.partition ((<=) h) t in (sort l) @ h::(sort r) Quicksort in OCaml!

Plan for Next ~5 Weeks 1) Fast Forward Rapid introduction to what s in OCaml 2) Rewind 3) Slow Motion Go over the pieces individually!

CSE 130 [Spring 2014] Programming Languages Introduction to OCaml! Ravi Chugh!

ML: History and Dialects Meta Language Designed by Robin Milner To manipulate theorems & proofs Several dialects: Standard ML (SML) Original syntax Objective Caml: (OCaml) The PL for the discerning hacker State-of-the-art, extensive library, tool, user support F# (ML +.NET) released in Visual Studio!

ML s Holy Trinity Expression! Value! Type! Everything is an expression Everything evaluates to a value Everything has a type!

Interacting with ML Read-Eval-Print Loop (REPL) Repeat: 1. System reads expression e 2. System evaluates e to get value v 3. System prints value v and type t What are these expressions, values and types?!

OCaml REPL Demo: ocaml-top on ieng6 Extended demo in Section tomorrow We will collect data from your submissions to learn about usability of error messages, etc. in practice o More details to follow!

Base Type: Integers 2! 2! 2+2! 4! 2 * (9+10)! 38! 2 * (9+10) -12! 26! int! Complex expressions using operators : (why the quotes?) +, -, * div, mod!

Base Type: Strings ab! ab ^ xy! ab! abxy! string! Complex expressions using operators : (why the quotes?) Concatenation ^!

Base Type: Booleans true! false! true! false! 1 < 2! true! aa = pq! ( aa = pq ) && (1<2)! ( aa = aa ) && (1<2)! false! false! true! bool! Complex expressions using operators : Relations : =, <, <=, >= &&,, not!

Type Errors (2+3) ( a = b )! pq ^ 9! (2 + a )! Untypable expression is rejected No casting, No coercing Fancy algorithm to catch errors ML s single most powerful feature (why?)!

ML s Holy Trinity Run-time ( Dynamic ) Expressions (Syntax) Values (Semantics) Compile-time ( Static ) Types 1. Enter an expression e 2. ML infers a type t or emits an error 3. ML evaluates expression e down to a value v 4. Value v is guaranteed to have type t!

So Far, A Fancy Calculator What do we need next?!

Complex Type: Tuples (Products) (2+2, 7>8);! (4,false)! int * bool!

Complex Type: Tuples (Products) (9-3, ab ^ cd,(2+2,7>8))! (6, abcd,(4,false))! (int * string * (int * bool))! Pairs, Triples, Quadruples, Nesting: Everything is an expression Nest tuples in tuples!

Complex Type: Lists [];! []! a list Unbounded size Can have lists of anything (e.g. lists of lists) But! [1;2;3];! [1;2;3]! int list [1+1;2+2;3+3;4+4];! [2;4;6;8]! int list [ a ; b ; c ^ d ];! [ a ; b ; cd ]! string list [(1, a ^ b );(3+4, c )];! [(1, ab );(7, c )]! (int*string) list [[1];[2;3];[4;5;6]];! [[1];[2;3];[4;5;6]];! (int list) list

Complex Type: Lists [1; pq ];! All elements must have same type!

Complex Type: Lists List operator Cons! :: 1::[];! [1]! int list! 1::[2;3];! [1;2;3]! int list! a ::[ b ; c ];! [ a ; b ; c ]! string list! Can only cons element to a list of same type 1::[ b ; cd ];!

Lists: Cons truct Nil operator []! []=>[]! []: a list Cons operator 1::[2;3]! [1;2;3] int list e1:t e2: T list! e1::e2 : T list e1=>v1 e2=> v2! e1::e2 => v1::v2!

Complex Type: Lists List operator Append! @ [1;2]@[3;4;5];! [1;2;3;4;5]! int list [ a ]@[ b ];! [ a ; b ]! string list []@[1];! [1]! int list Can only append two lists 1 @ [2;3];! of the same type [1] @ [ a ; b ];!

Complex Type: Lists List operator Head! List.hd hd [1;2];! 1! int hd ([ a ]@[ b ]);! a! string ML types can t catch some errors though hd []! Exception: Failure hd.! (ML does infer a type )

Complex Type: Lists List operator Tail! List.tl tl [1;2;3];! [2;3]! int list tl ([ a ]@[ b ]);! [ b ]! string list The tail of empty list is a run-time error tl []! Exception: Failure hd.! Expressiveness of type systems is an active area of research!

Lists: Deconstruct (or Destruct) Head e :T list e => v1::v2! hd e : T! hd e => v1! Tail e :T list tl e : T list! e => v1::v2! tl e => v2! (hd [[];[1;2;3]]) = (hd [[];[ a ]])! int list e 1 :T e 2 :T! e 1 = e 2 : bool string list

Recap: Tuples vs. Lists What s the difference? Tuples: Different types, but fixed number: Lists: pair = 2 elts (3, abcd,(3.5,4.2)) (int * string * (float * float)) triple = 3 elts Same type, unbounded number: Syntax: (3, abcd ) (int * string) [3;4;5;6;7] int list Tuples = comma Lists = semicolon!