Programming Languages Dan Grossman 2013

Slides:



Advertisements
Similar presentations
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Advertisements

Programming Languages Section 1 1 Programming Languages Section 1. SML Fundamentals Xiaojuan Cai Spring 2015.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
CSE341: Programming Languages Lecture 4 Records (“each of”), Datatypes (“one of”), Case Expressions Dan Grossman Fall 2011.
CSE341: Programming Languages Lecture 5 Pattern-Matching Dan Grossman Fall 2011.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Fall 2011.
0 PROGRAMMING IN HASKELL Chapter 4 - Defining Functions.
Introduction to ML - Part 2 Kenny Zhu. What is next? ML has a rich set of structured values Tuples: (17, true, “stuff”) Records: {name = “george”, age.
Crash course on SML Wojciech Moczydłowski SML – functional programming language Complete formal semantics Extremely convenient for writing compilers, interpreters,
Patterns in OCaml functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are.
Chapter 9: Functional Programming in a Typed Language.
CSE 341 : Programming Languages Lecture 2 Functions, Pairs, Lists Zach Tatlock Spring 2014.
0 PROGRAMMING IN HASKELL Chapter 4 - Defining Functions.
Introduction to Objective Caml. General comments ML is a purely functional language--there are (almost) no side effects There are two basic dialects of.
List Operations CSCE 314 Spring CSCE 314 – Programming Studio Tuple and List Patterns Pattern matching with wildcards for tuples fst (a, _) = a.
1 Objective Caml (Ocaml) Aaron Bloomfield CS 415 Fall 2005.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2013.
Programming Languages and Compilers (CS 421)
Conditional Expressions
ML: a quasi-functional language with strong typing
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2017.
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2017.
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
A lightening tour in 45 minutes
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2017.
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Spring 2016.
Sequences Objectives:
Nicholas Shahan Spring 2016
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Spring 2013.
An aggregation mechanism
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2018.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2013.
CSE 341 Section 2 Winter 2018 Adapted from slides by Nick Mooney, Nicholas Shahan, Patrick Larson, and Dan Grossman.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE 341 Section 5 Winter 2018.
4. Dividing Computing with Pattern Matching in F#
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Spring 2017.
PROGRAMMING IN HASKELL
Spencer Pearson Spring 2017
CSE 341 Section 2 Nick Mooney Spring 2017
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Zach Tatlock Winter 2018.
CSE 3302 Programming Languages
Dan Grossman / Eric Mullen Autumn 2017
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2016.
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2019.
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Spring 2019.
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
Sequences Objectives:
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Autumn 2017.
Presentation transcript:

Programming Languages Dan Grossman 2013 Introducing Lists

Dan Grossman, Programming Languages Lists Despite nested tuples, the type of a variable still “commits” to a particular “amount” of data In contrast, a list: Can have any number of elements But all list elements have the same type Need ways to build lists and access the pieces… Jan-Mar 2013 Dan Grossman, Programming Languages

e1::e2 (* pronounced “cons” *) Building Lists The empty list is a value: In general, a list of values is a value; elements separated by commas: If e1 evaluates to v and e2 evaluates to a list [v1,…,vn], then e1::e2 evaluates to [v,…,vn] [] [v1,v2,…,vn] e1::e2 (* pronounced “cons” *) Jan-Mar 2013 Dan Grossman, Programming Languages

Dan Grossman, Programming Languages Accessing Lists Until we learn pattern-matching, we will use three standard-library functions null e evaluates to true if and only if e evaluates to [] If e evaluates to [v1,v2,…,vn] then hd e evaluates to v1 (raise exception if e evaluates to []) If e evaluates to [v1,v2,…,vn] then tl e evaluates to [v2,…,vn] Notice result is a list Jan-Mar 2013 Dan Grossman, Programming Languages

Type-checking list operations Lots of new types: For any type t, the type t list describes lists where all elements have type t Examples: int list bool list int list list (int * int) list (int list * int) list So [] can have type t list list for any type SML uses type 'a list to indicate this (“quote a” or “alpha”) For e1::e2 to type-check, we need a t such that e1 has type t and e2 has type t list. Then the result type is t list null : 'a list -> bool hd : 'a list -> 'a tl : 'a list -> 'a list Jan-Mar 2013 Dan Grossman, Programming Languages