Functional Programming

Similar documents
CMSC 330: Organization of Programming Languages. Functional Programming with OCaml

COS 326 Functional programming: an elegant weapon for the modern age

Functional Programming Lecture 13: FP in the Real World

CSCI-GA Scripting Languages

Introduction to OCaml

Refactoring to Functional. Hadi Hariri

ITT8060 Advanced Programming

Scope and Introduction to Functional Languages. Review and Finish Scoping. Announcements. Assignment 3 due Thu at 11:55pm. Website has SML resources

CSE341: Programming Languages Interlude: Course Motivation. Zach Tatlock Winter 2018

Concepts of Programming Languages

Functional Programming Lecture 1: Introduction

Introduction to ML. Based on materials by Vitaly Shmatikov. General-purpose, non-c-like, non-oo language. Related languages: Haskell, Ocaml, F#,

Introduction to Functional Programming and Haskell. Aden Seaman

Quick announcement. Midterm date is Wednesday Oct 24, 11-12pm.

h0ps://

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

Functional Programming. Big Picture. Design of Programming Languages

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Functional Programming Principles in Scala. Martin Odersky

Introduction to SML Getting Started

A Practical Optional Type System for Clojure. Ambrose Bonnaire-Sergeant

The design of a programming language for provably correct programs: success and failure

CSCI 2041: Introduction

Introduction. chapter Functions

Robot Programming with Lisp

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

Stop coding Pascal. Saturday, April 6, 13

Simply-Typed Lambda Calculus

Lecture 8: Summary of Haskell course + Type Level Programming

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

15. Functional Programming

Functional Programming and Haskell

CSE 341: Programming Languages

CS 11 Haskell track: lecture 1

SD314 Outils pour le Big Data

PL Categories: Functional PLs Introduction to Haskell Haskell: Functions

CIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML)

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

FUNCTIONAL PROGRAMMING

Welcome to. Instructor Marc Pomplun CS 470/670. Introduction to Artificial Intelligence 1/26/2016. Spring Selectivity in Complex Scenes

Functional Programming

Language Sequence. The Algol Family and ML. Algol 60 Sample. Algol 60. Some trouble spots in Algol 60. Algol Joke. John Mitchell

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

Announcements. CSCI 334: Principles of Programming Languages. Lecture 5: Fundamentals III & ML

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Basics

CPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia

Swift, functional programming, and does it matter? Alexis

Com S 541. Programming Languages I

Software System Design and Implementation

Introduction to Functional Programming

Functional programming in C#

A Func'onal Introduc'on. COS 326 David Walker Princeton University

IA010: Principles of Programming Languages

Introduction to Functional Programming in Haskell 1 / 56

Programs and Proofs in Isabelle/HOL

The Algol family and ML

Is Functional Programming (FP) for me? ACCU Conference 2008 Hubert Matthews

INTRODUCTION TO FUNCTIONAL PROGRAMMING

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

CSCI.4430/6969 Programming Languages Lecture Notes

Chapter 11 :: Functional Languages

CS252 Advanced Programming Language Principles. Prof. Tom Austin San José State University Fall 2013

CS Lecture 6: Map and Fold. Prof. Clarkson Spring Today s music: Selections from the soundtrack to 2001: A Space Odyssey

JVM ByteCode Interpreter

Programming Languages

Combining Programming with Theorem Proving

Introduction to Functional Programming in Racket. CS 550 Programming Languages Jeremy Johnson

Chapter 15. Functional Programming Languages

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Formal Systems and their Applications

Recursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion

A Brief Introduction to Standard ML

CPS 506 Comparative Programming Languages. Programming Language Paradigm

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

Scala, Your Next Programming Language

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

Programming Languages and Techniques (CIS120)

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes

Verifying Concurrent ML programs

A Pragmatic Case For. Static Typing

J. Barkley Rosser, 81, a professor emeritus of mathematics and computer science at the University of Wisconsin who had served in government, died

Part I Basic Concepts 1

The Algol family and ML

Recursion. Tjark Weber. Functional Programming 1. Based on notes by Sven-Olof Nyström. Tjark Weber (UU) Recursion 1 / 37

CS457/557 Functional Languages

Functional Programming

Software System Design and Implementation

Polymorphism and Type Inference

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

3. Functional Programming. Oscar Nierstrasz

Programming with Math and Logic

Programming Languages (CSCI 4430/6430) History, Syntax, Semantics, Essentials, Paradigms

More Lambda Calculus and Intro to Type Systems

Imperative languages

Classical Themes of Computer Science

SOFTWARE VERIFICATION AND COMPUTER PROOF (lesson 1) Enrico Tassi Inria Sophia-Antipolis


Concepts in Programming Languages

All you need is fun. Cons T Åhs Keeper of The Code

Transcription:

The Meta Language (ML) and Functional Programming Daniel S. Fava danielsf@ifi.uio.no Department of informatics University of Oslo, Norway

Motivation ML Demo

Which programming languages are functional?

Which programming languages are functional? Lambda calculus 1930 (a model of computation)

Which programming languages are functional? Lambda calculus 1930 (a model of computation) Lisp 1950 ML 1973

Which programming languages are functional? Lambda calculus 1930 (a model of computation) Lisp 1950 dynamically typed ML 1973 statically typed

Which programming languages are functional? Lambda calculus 1930 (a model of computation) Lisp 1950 dynamically typed Scheme 1970 Racket 1995 ML 1973 statically typed

Which programming languages are functional? Lambda calculus 1930 (a model of computation) Lisp 1950 dynamically typed Scheme 1970 Racket 1995 ML 1973 statically typed Standard ML or SML Caml 1985 OCaml 1996

Which programming languages are functional? Lambda calculus 1930 (a model of computation) Lisp 1950 dynamically typed Scheme 1970 Racket 1995 ML 1973 statically typed Standard ML or SML Caml 1985 OCaml 1996 Haskell 1990

Which programming languages are functional? Lambda calculus 1930 (a model of computation) Lisp 1950 dynamically typed Scheme 1970 Racket 1995 ML 1973 statically typed Standard ML or SML Caml 1985 OCaml 1996 Haskell 1990 Erlang 1986, Scala 2004, Clojure 2007 (multi-paradigm)

Why another programming paradigm?

Why another programming paradigm? A different way of thinking

Why another programming paradigm? A different way of thinking Non-functional PLs borrowing functional constructs

Why another programming paradigm? A different way of thinking Non-functional PLs borrowing functional constructs JavaScript, Python, Lua, PHP, C++11, C#...

Why another programming paradigm? A different way of thinking Non-functional PLs borrowing functional constructs JavaScript, Python, Lua, PHP, C++11, C#... MapReduce

Why another programming paradigm? A different way of thinking Non-functional PLs borrowing functional constructs JavaScript, Python, Lua, PHP, C++11, C#... MapReduce Debatable

Why another programming paradigm? A different way of thinking Non-functional PLs borrowing functional constructs JavaScript, Python, Lua, PHP, C++11, C#... MapReduce Debatable easier to reason about and to prove properties of

Why another programming paradigm? A different way of thinking Non-functional PLs borrowing functional constructs JavaScript, Python, Lua, PHP, C++11, C#... MapReduce Debatable easier to reason about and to prove properties of more compact, simpler code

Why another programming paradigm? A different way of thinking Non-functional PLs borrowing functional constructs JavaScript, Python, Lua, PHP, C++11, C#... MapReduce Debatable easier to reason about and to prove properties of in the eye of the beholder more compact, simpler code

Why another programming paradigm? A different way of thinking Non-functional PLs borrowing functional constructs JavaScript, Python, Lua, PHP, C++11, C#... MapReduce Debatable easier to reason about and to prove properties of in the eye of the beholder more compact, simpler code problems can be easier to express given certain idioms match the language to the problem

What is functional programming? [100]a [100]a [100]a [100]a

What is functional programming? It is programming with: [100]a [100]a [100]a [100]a

What is functional programming? It is programming with: first-class and higher-order functions [100]a [100]a [100]a

What is functional programming? It is programming with: first-class and higher-order functions purity [100]a [100]a

What is functional programming? It is programming with: first-class and higher-order functions purity pattern matching [100]a

What is functional programming? It is programming with: first-class and higher-order functions purity pattern matching recursion

first-class and higher-order functions purity pattern matching recursion

first-class and higher-order functions Currying Closures purity pattern matching recursion

first-class and higher-order functions Currying Closures purity Statements versus Expressions and Declarations Side effects versus Effect free Immutability Referential transparency pattern matching recursion

first-class and higher-order functions Currying Closures purity Statements versus Expressions and Declarations Side effects versus Effect free Immutability Referential transparency pattern matching constructors and pattern matching data structures Nat, Lists, Trees, etc recursion

first-class and higher-order functions Currying Closures purity Statements versus Expressions and Declarations Side effects versus Effect free Immutability Referential transparency pattern matching constructors and pattern matching data structures Nat, Lists, Trees, etc recursion tail recursion termination and total functions continuations and continuation passing style (CPS)

The Meta Language (ML) ML is a functional programming language with imperative features,

The Meta Language (ML) ML is a functional programming language with imperative features, it was part of project to create an interactive theorem prover.

The Meta Language (ML) ML is a functional programming language with imperative features, it was part of project to create an interactive theorem prover. Logic for Computable Functions (LCF)

The Meta Language (ML) ML is a functional programming language with imperative features, it was part of project to create an interactive theorem prover. Logic for Computable Functions (LCF) Project headed by Robin Milner in 1972.

The Meta Language (ML) ML is a functional programming language with imperative features, it was part of project to create an interactive theorem prover. Logic for Computable Functions (LCF) Project headed by Robin Milner in 1972. notation for programs

The Meta Language (ML) ML is a functional programming language with imperative features, it was part of project to create an interactive theorem prover. Logic for Computable Functions (LCF) Project headed by Robin Milner in 1972. notation for programs notation for proofs (eg. proof that quicksort returns a sorted array)

The Meta Language (ML) ML is a functional programming language with imperative features, it was part of project to create an interactive theorem prover. Logic for Computable Functions (LCF) Project headed by Robin Milner in 1972. notation for programs notation for proofs (eg. proof that quicksort returns a sorted array) write programs that search for proofs

The Meta Language (ML) ML is a functional programming language with imperative features, it was part of project to create an interactive theorem prover. Logic for Computable Functions (LCF) Project headed by Robin Milner in 1972. notation for programs notation for proofs (eg. proof that quicksort returns a sorted array) write programs that search for proofs have a program that checks a proof

tactic : formula proof

Composition of tactics tactic : formula proof

tactic : formula proof Composition of tactics Take tactics as input and return a more complex tactic

tactic : formula proof Composition of tactics Take tactics as input and return a more complex tactic Proof checking

tactic : formula proof Composition of tactics Take tactics as input and return a more complex tactic Proof checking theorem abstract data type

tactic : formula proof Composition of tactics Take tactics as input and return a more complex tactic Proof checking theorem abstract data type theorems derivable only via inference rules given by theorem

tactic : formula proof Composition of tactics Take tactics as input and return a more complex tactic Proof checking theorem abstract data type theorems derivable only via inference rules given by theorem calling tactic on a formula can either:

tactic : formula proof Composition of tactics Take tactics as input and return a more complex tactic Proof checking theorem abstract data type theorems derivable only via inference rules given by theorem calling tactic on a formula can either: terminate and return a proof, or

tactic : formula proof Composition of tactics Take tactics as input and return a more complex tactic Proof checking theorem abstract data type theorems derivable only via inference rules given by theorem calling tactic on a formula can either: terminate and return a proof, or diverge, which means run forever, or

tactic : formula proof Composition of tactics Take tactics as input and return a more complex tactic Proof checking theorem abstract data type theorems derivable only via inference rules given by theorem calling tactic on a formula can either: terminate and return a proof, or diverge, which means run forever, or raise an exception

tactic : formula proof Composition of tactics Higher-order functions Take tactics as input and return a more complex tactic Proof checking theorem abstract data type theorems derivable only via inference rules given by theorem calling tactic on a formula can either: terminate and return a proof, or diverge, which means run forever, or raise an exception

tactic : formula proof Composition of tactics Higher-order functions Take tactics as input and return a more complex tactic Proof checking theorem abstract data type Expressive and sound type system theorems derivable only via inference rules given by theorem calling tactic on a formula can either: terminate and return a proof, or diverge, which means run forever, or raise an exception

tactic : formula proof Composition of tactics Higher-order functions Take tactics as input and return a more complex tactic Proof checking theorem abstract data type Expressive and sound type system theorems derivable only via inference rules given by theorem calling tactic on a formula can either: terminate and return a proof, or diverge, which means run forever, or raise an exception First language with type-safe exceptions

Read-Evaluate-Print Loop (REPL)

Read-Evaluate-Print Loop (REPL) In ML, expressions are type-checked after R and before E