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 Exceptions.1 Standard ML Exceptions. ML Exceptions.2 Exceptions – The Need  An extensive part of the code is error handling  A function F can return.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Winter 2013.
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.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
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,
CSE 341 Programming Languages Racket Datatype Style Programming Zach Tatlock Spring 2014.
Programming Languages Section 2 1 Programming Languages Section 2. Building New Types Xiaojuan Cai Spring 2015.
CSE 341 : Programming Languages Lecture 4 Records, Datatypes, Case Expressions Zach Tatlock Spring 2014.
CSE 341 : Programming Languages Lecture 5 More Datatypes and Pattern Matching Zach Tatlock Spring 2014.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2013.
Programming Languages Dan Grossman 2013 Datatype-Programming in Racket Without Structs.
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 3 Local Bindings; Options; Benefits of No Mutation Dan Grossman Winter 2013.
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
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 3 Local Bindings; Options; Benefits of No Mutation Dan Grossman Spring 2017.
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Programming Languages Dan Grossman 2013
Programming Languages Dan Grossman 2013
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 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2013.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs 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.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2018.
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.
CSE341: Programming Languages Lecture 3 Local Bindings; Options; Benefits of No Mutation Dan Grossman Spring 2013.
CSE341: Programming Languages Lecture 3 Local Bindings; Options; Benefits of No Mutation Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2018.
CSE341: Programming Languages Lecture 12 Equivalence
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
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 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 12 Equivalence
CSE341: Programming Languages Lecture 3 Local Bindings; Options; Benefits of No Mutation 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.
CSE341: Programming Languages Lecture 3 Local Bindings; Options; Benefits of No Mutation Dan Grossman Winter 2018.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Doug Woos Winter 2018.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
CSE341: Programming Languages Lecture 3 Local Bindings; Options; Benefits of No Mutation Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 3 Local Bindings; Options; Benefits of No Mutation Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions 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
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2019.
Presentation transcript:

Programming Languages Dan Grossman 2013 Datatype Bindings

Dan Grossman, Programming Languages Datatype bindings A “strange” (?) and totally awesome (!) way to make one-of types: A datatype binding datatype mytype = TwoInts of int * int | Str of string | Pizza Adds a new type mytype to the environment Adds constructors to the environment: TwoInts, Str, and Pizza A constructor is (among other things), a function that makes values of the new type (or is a value of the new type): TwoInts : int * int -> mytype Str : string -> mytype Pizza : mytype Jan-Mar 2013 Dan Grossman, Programming Languages

Dan Grossman, Programming Languages The values we make datatype mytype = TwoInts of int * int | Str of string | Pizza Any value of type mytype is made from one of the constructors The value contains: A “tag” for “which constructor” (e.g., TwoInts) The corresponding data (e.g., (7,9)) Examples: TwoInts(3+4,5+4) evaluates to TwoInts(7,9) Str(if true then "hi" else "bye") evaluates to Str("hi") Pizza is a value Jan-Mar 2013 Dan Grossman, Programming Languages

Dan Grossman, Programming Languages Using them So we know how to build datatype values; need to access them There are two aspects to accessing a datatype value Check what variant it is (what constructor made it) Extract the data (if that variant has any) Notice how our other one-of types used functions for this: null and isSome check variants hd, tl, and valOf extract data (raise exception on wrong variant) ML could have done the same for datatype bindings For example, functions like “isStr” and “getStrData” Instead it did something better Jan-Mar 2013 Dan Grossman, Programming Languages