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

Similar documents
Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

Introduction to Nate Foster Spring 2018

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont.

Background. CMSC 330: Organization of Programming Languages. Useful Information on OCaml language. Dialects of ML. ML (Meta Language) Standard ML

Functional Programming

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

Introduction to OCaml

CS 3110 Lecture 1 Course Overview

Refactoring to Functional. Hadi Hariri

Real World Ocaml Functional Programming For The Masses

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

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

Functional Programming Principles in Scala. Martin Odersky

Functional Programming in Java. CSE 219 Department of Computer Science, Stony Brook University

Functional Programming

Functional Programming Lecture 13: FP in the Real World

Concepts of Programming Languages

CSCI-GA Scripting Languages

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

CMSC 330: Organization of Programming Languages. OCaml Expressions and Functions

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

ITT8060 Advanced Programming

Functional Programming. Big Picture. Design of Programming Languages

COSE212: Programming Languages. Lecture 0 Course Overview

3. Functional Programming. Oscar Nierstrasz

CMSC 330: Organization of Programming Languages. Administrivia

Chapter 11 :: Functional Languages

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

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

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

Mutation. COS 326 Andrew W. Appel Princeton University. slides copyright David Walker and Andrew W. Appel

CHAPTER ONE OVERVIEW. 1.1 Continuation-passing style

Introduction to Functional Programming and Haskell. Aden Seaman

h0ps://

Mutation. COS 326 David Walker Princeton University

G Programming Languages - Fall 2012

Comp 333: Concepts of Programming Languages Fall 2016

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

Key components of a lang. Deconstructing OCaml. In OCaml. Units of computation. In Java/Python. In OCaml. Units of computation.

Haskell in the corporate environment. Jeff Polakow October 17, 2008

Programming Language Pragmatics

Concepts of program design Exam January 31, 13:30 16:30

The story so far. Elements of Programming Languages. While-programs. Mutable vs. immutable

CS558 Programming Languages

What is programming? Elements of Programming Languages. From machine code to programming languages. What is a programming language?

Talking to the Rooster Communicating with Coq via XML. Tom Hutchinson

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

Functional Programming and Haskell

An Introduction To Object Oriented Programming 3rd Edition

Programming Languages and Techniques (CIS120)

CS Lectures 2-3. Introduction to OCaml. Polyvios Pratikakis

Programming Languages and Techniques (CIS120)

Polymorphism and Type Inference

Haskell in the Software Industry

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Rust for high level applications. Lise Henry

CSCI 2041: Introduction

Back to OCaml. Summary of polymorphism. Example 1. Type inference. Example 2. Example 2. Subtype. Polymorphic types allow us to reuse code.

Functional Languages. Hwansoo Han

Scala, Your Next Programming Language

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

CS6202: Advanced Topics in Programming Languages and Systems Lecture 0 : Overview

A Pragmatic Case For. Static Typing

Introduction to Functional Programming in Haskell 1 / 56

CMSC 330: Organization of Programming Languages. Administrivia

CS558 Programming Languages

Frege. purely functional programming on the JVM. GOTO Berlin 2015

Programs and Proofs in Isabelle/HOL

Introduction to SML Getting Started

Introduction to Concepts in Functional Programming. CS16: Introduction to Data Structures & Algorithms Spring 2017

Types and Type Inference

Languages and Compilers

Functional Programming

Monday Feb 16, 5pm. solve these equalities. Midterm Thursday Feb 12. covers only ocaml part of the course, assignments 1 through 3.

CMSC330 Spring 2008 Final Exam

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

Functional Programming Concepts for Data Processing

Reasoning About Imperative Programs. COS 441 Slides 10

SED 508. Transcript EPISODE 508 [INTRODUCTION]

CS 11 Haskell track: lecture 1

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

Programming language design and analysis

Language Translation, History. CS152. Chris Pollett. Sep. 3, 2008.

Imperative languages

INF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes

Seminar on Languages for Scientific Computing Aachen, 6 Feb Navid Abbaszadeh.

CSCE 314 Programming Languages

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

September 10,

Conclusions and further reading

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CMSC330 Fall 2013 Practice Problems 6 Solutions

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

CS457/557 Functional Languages

Transcription:

CMSC 330: Organization of Programming Languages Functional Programming with OCaml 1

What is a functional language? A functional language: defines computations as mathematical functions discourages use of mutable state State: the information maintained by a computation Mutable: can be changed 2

Functional vs. Imperative Functional languages: Higher level of abstraction Easier to develop robust software Immutable state: easier to reason about software Imperative languages: Lower level of abstraction Harder to develop robust software Mutable state: harder to reason about software 3

Imperative Programming Commands specify how to compute, by destructively changing state: x = x+1; a[i] = 42; p.next = p.next.next; Functions/methods have side effects: int wheels(vehicle v) { v.size++; return v.numwheels; } 4

Mutability The fantasy of mutability: It's easy to reason about: the machine does this, then this... The reality of mutability: Machines are good at complicated manipulation of state Humans are not good at understanding it! mutability breaks referential transparency: ability to replace an expression with its value without affecting the result In math, if f(x)=y, then you can substitute y anywhere you see f(x) In imperative languages, you cannot: f might have side effects, so computing f(x) at one time might result in different value at another 5

Mutability The fantasy of mutability: There is a single state The computer does one thing at a time The reality of mutability: There is no single state Programs have many threads, spread across many cores, spread across many processors, spread across many computers... each with its own view of memory There is no single program Most applications do many things at one time 6

Functional programming Expressions specify what to compute Variables never change value Like mathematical variables Functions (almost) never have side effects The reality of immutability: No need to think about state Easier (and more powerful) ways to build correct programs and concurrent programs 7

Key Features of ML First-class functions Functions can be parameters to other functions ( higher order ) and return values, and stored as data Favor immutability ( assign once ) Data types and pattern matching Convenient for certain kinds of data structures Type inference No need to write types in the source language But the language is statically typed Supports parametric polymorphism Generics in Java, templates in C++ Like Ruby, Java,...: exceptions and garbage collection 8

Why study functional programming? Functional languages predict the future: Garbage collection Java [1995], LISP [1958] Parametric polymorphism (generics) Java 5 [2004], ML [1990] Higher-order functions C#3.0 [2007], Java 8 [2014], LISP [1958] Type inference C++11 [2011], Java 7 [2011] and 8, ML [1990] Pattern matching ML [1990], Scala [2002], Java X [201?] http://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html 9

Why study functional programming? Functional languages in the real world 10

ML-style (Functional) Languages ML (Meta Language) Univ. of Edinburgh, 1973 Part of a theorem proving system LCF Standard ML Bell Labs and Princeton, 1990; Yale, AT&T, U. Chicago OCaml (Objective CAML) INRIA, 1996 French Nat l Institute for Research in Computer Science O is for objective, meaning objects (which we ll ignore) Haskell (1998): lazy functional programming Scala (2004): functional and OO programming 11

Useful Information on OCaml language Translation available on the class webpage Developing Applications with Objective Caml Webpage also has link to another book Introduction to the Objective Caml Programming Language 12

More Information on OCaml Book designed to introduce and advance understanding of OCaml Authors use OCaml in the real world Introduces new libraries, tools Free HTML online realworldocaml.org 13

Coding Guidelines We will not grade on style, but style is important Recommended coding guidelines: https://ocaml.org/learn/tutorials/guidelines.html 14