341 midterm review Xinrong Zhao Autumn 2018.

Slides:



Advertisements
Similar presentations
ML Exceptions.1 Standard ML Exceptions. ML Exceptions.2 Exceptions – The Need  An extensive part of the code is error handling  A function can return.
Advertisements

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.
CSE341: Programming Languages Lecture 6 Tail Recursion, Accumulators, Exceptions Dan Grossman Fall 2011.
CSE 341 : Programming Languages Lecture 6 Fancy Patterns, Exceptions, Tail Recursion Zach Tatlock Spring 2014.
CSE 341 Programming Languages Racket Datatype Style Programming Zach Tatlock Spring 2014.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
A Second Look At ML 1. Outline Patterns Local variable definitions A sorting example 2.
Chapter SevenModern Programming Languages1 A Second Look At ML.
Interpreters and Higher-Order Functions CSE 413 Autumn 2008 Credit: CSE341 notes by Dan Grossman.
Chapter 14 Functions.
CSE341: Programming Languages Lecture 11 Type Inference
Functions CSC 358/
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2017.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Winter 2013.
Section 2 – CSE341 Patrick Larson, Spring 2013.
Expanded Recursive Diagrams OCAML rapid tour, day 2
CSE341: Programming Languages Lecture 9 Function-Closure Idioms
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 9 Function-Closure Idioms
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 9 Function-Closure Idioms
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Autumn 2018.
CSE 341 Section 4 Nick Mooney Spring 2017.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2013.
Objective caml Daniel Jackson MIT Lab for Computer Science 6898: Advanced Topics in Software Design March 18, 2002.
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 11 Type Inference
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2013.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE341: Programming Languages Lecture 9 Function-Closure Idioms
CSE 341 Section 5 Winter 2018.
CSE341: Programming Languages Lecture 9 Function-Closure Idioms
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Autumn 2018.
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 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 9 Function-Closure Idioms
CSE341: Programming Languages Section 3 Function Patterns Tail Recursion Winter 2018.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2016.
CSE-321 Programming Languages Introduction to Functional Programming
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 9 Function-Closure Idioms
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 7 First-Class Functions
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures 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 7 First-Class Functions
Higher-Order Functions and Closures
CSE341: Programming Languages Lecture 16 Datatype-Style Programming With Lists or Structs Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Dan Grossman Autumn 2017.
Presentation transcript:

341 midterm review Xinrong Zhao Autumn 2018

Today’s content Macros: Brief Review + (Practice Questions) You can bring one side of one 8.5x11in piece of paper Brief Review + (Practice Questions) Module 8.5 + Signature 2 Type Inference 5 Lexical Scope 4.5 Currying 4 Higher order function 3.5 Tail recursion 2 Datatypes, pattern matching 0.5

THINK-PAIR-Share-Report Think individually pair with person next to you share with your neighbor get together to this question for report

Module & SIGNATURE Signature specifies things with certain (or more general) types must exist in module things can be accessible outside module Module can have no signature or contain more things than its signature Question: Spring 2016 #6 (e’) What if having S1 with signature INTERVAL1 and S2 with signature INTERVAL2? (f’) What if having S1 with signature INTERVAL2 and S2 with signature INTERVAL1? Would S2.size (S1.make (5,~5)) type-check?

Type INFERENCE Set up formula Collect facts If there is a conflict then type inference fails (the thing doesn’t type-check) Question: (g) & (h) on the same question

Lexical scope The body of a function is evaluated in the environment where the function is defined. Function Closure = code + environment when we define the function Question: Spring 2013 #3 the closure overall is “closed” — it has everything it needs to produce a function result given a function argument

Higher order function & Currying Function that takes functions as argument or returns function Currying: Currying function takes “multiple arguments” and returns function closure except on the last argument Question: Spring 2016 #4

DATATYPES & Pattern matching Datatype bindings have “One-of” Types Constructors taking some arguments to get this datatype Pattern-matching example for One-of types (datatypes) (* need to match each constructor option has *) case opt of NONE => … | SOME i => … Each-of types (tuple, record) case triple of (0, 0, _) => 0 | (a, b, _) => a + b Self-reference types (list) case int_tuple_list of [] => 0 | (a, b) :: c => a + b

Tail recursion No more to do after recursive call except return the result (there is nothing more for the caller to do after the callee returns except return the callee’s result) Example: (* assume n >= 0, f1 is not tail-recursive, but f2 is, why? *) fun f1 (n) = if n = 0 then 0 else f1(n-1) + 1 fun f2 (n) = if n = 0 then 0 else f2(n-1) Question: Spring 2013 #1