Section 2 – CSE341 Patrick Larson, Spring 2013.

Slides:



Advertisements
Similar presentations
Modelling & Datatypes John Hughes. Software Software = Programs + Data.
Advertisements

Modelling & Datatypes Koen Lindström Claessen. Software Software = Programs + Data.
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 4 Records (“each of”), Datatypes (“one of”), Case Expressions Dan Grossman Fall 2011.
Modelling & Datatypes Koen Lindström Claessen. Software Software = Programs + Data.
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.
Two Way Tables Venn Diagrams Probability. Learning Targets 1. I can use a Venn diagram to model a chance process involving two events. 2. I can use the.
CSE 341 Programming Languages Racket Datatype Style Programming Zach Tatlock Spring 2014.
Draw 3 cards without replacement from a standard 52 card deck. What is the probability that: 1.They are all red ? 2.At least one is black ? 3.They are.
1 Lecture 2 Control Structures: Part 1 Selection: else / if and switch.
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.
Arrangements and Selections (and how they may be counted)
Test Data Generators. Why Distinguish Instructions? Functions always give the same result for the same arguments Instructions can behave differently on.
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2017.
Evaluating Algebraic Expressions
11/7/16 Entry 173 – Objective I will review and continue developing my understanding of uniform probability models, including the complement of an event.
The Addition Rule.
Classroom Expectations
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2013.
Definitions: Random Phenomenon:
Expanded Recursive Diagrams OCAML rapid tour, day 2
Test Data Generators.
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.
Chapter 10: Counting Methods
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.
Section 2 – CSE341 Konstantin Weitz.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2018.
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.
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2018.
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE 341 Section 2 Winter 2018 Adapted from slides by Nick Mooney, Nicholas Shahan, Patrick Larson, and Dan Grossman.
CSE 341 Section 5 Winter 2018.
CSE 341 PL Section 2 Justin Harjanto.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2017.
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.
Spencer Pearson Spring 2017
Strong’s GMAS Review, Week 5, Problems 4 - 5
CSE 341 Section 2 Nick Mooney Spring 2017
Adapted from slides by Nicholas Shahan and Dan Grossman
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 7 First-Class Functions
Nicholas Shahan Spring 2016
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2016.
Section 12.2 Theoretical Probability
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE 341 Section 2.
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Doug Woos Winter 2018.
Section 12.2 Theoretical Probability
Homework Due Friday.
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE341: Programming Languages Lecture 5 More Datatypes and Pattern-Matching Dan Grossman Spring 2019.
Section 12.2 Theoretical Probability
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.
Agenda Warmup Lesson 2.4 (String concatenation, primitive types, etc)
Presentation transcript:

Section 2 – CSE341 Patrick Larson, Spring 2013

Type Synonyms What if I want to call int * int * int a date? type date = int * int * int

Type Synonyms type vs datatype Datatype introduces a new type name, distinct from all existing types datatype suit = Club | Diamond | Heart | Spade datatype rank = Jack | Queen | King | Ace | Num of int Type is just another name type card = suit * rank The only way to construct values of the datatype is with the constructors Interchangeable in EVERY way. Write a function of type card -> bool It’s okay if the REPL prints suit * rank -> bool. Will print whatever it figures out first.

Type Synonym Why? For now, just for convenience. It doesn’t let us do anything new. Later in the course we will see another use related to modularity.

Type Generality Write a function that appends two string lists…

Type Generality We expected string list * string list -> string list But the type checker says ‘a list * ‘a list -> ‘a list Why is this okay?

Type Generality The type ‘a is more general More general types “can be used” as any less general type.

Type Generality The “more general” rule A type t1 is more general than the type t2 if you can take t1, replace its type variables consistently, and get t2

Write a contains function… Equality Types Write a contains function…

Equality Types Double quotes arise from use of the ‘=‘ operator We can only use ‘=‘ on types that can be compared Generality rules work the same, except substitution must be some type which can be compared with ‘=‘ Not everything is an equality type (real is not) Tuples / record / lists are equality types if and only if the components are equality types

If-then-else is just a case statement in disguise… Syntactic Sugar If-then-else is just a case statement in disguise…

Syntactic Sugar Pattern matching… If time allows, explain how type inference uses patterns, so that including type definitions is no longer necessary