# According to Larry Wall (designer of PERL): a language by geniuses! for geniuses. Lecture 7: Haskell. Haskell 98. Haskell (cont) - Type-safe!

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Lecture 7: Haskell CSC 131 Fall, 2014 Kim Bruce According to Larry Wall (designer of PERL): a language by geniuses for geniuses He s wrong at least about the latter part though you might agree when we talk about monads Haskell 98 Haskell (cont) Purely functional Functions are first-class values Statically scoped Strong, static typing via type inference - Type-safe Parametric polymorphism Type classes Rich type system including support for ADT s Non-strict (lazy) evaluation Imperative features emulated using monads. Garbage collection Compiled or interpreted. Named after Haskell Curry -- early contributor to lambda calculus and combinatory logic

2 Read Haskell Tutorials Using GHC All on links page from course web page I like Learn you a Haskell for greater good O Reilly text: Real World Haskell free on-line Print Haskell cheat sheet Use The Haskell platform, available at - to enter interactive mode type: ghci - :load myfile.hs -- :l also works - after changes type :reload myfile.hs - Control-d to exit - :set +t -- prints more type info when interactive - it is result of expression Built-in data types Unit has only ( ) Bool: True, False with not, &&, Int: 5, -5, with +, -, *, ^, =, /=, <, >, >=,... - div, mod defined as prefix operators (`div` infix) - Int fixed size (usually 64 bits) - Integer gives unbounded size Float, Double: 3.17, 2.4e17 w/ +, -, *, /, =, <, >, >=, <=, sin, cos, log, exp, sqrt, sin, atan. Char: n More Basic Types String = [Char], not really primitive - "hello"++" there", length list of Char - No substring, but `isinfixof` for all lists - Also isprefixof`, `issuffixof Prefix op w/out `` import Data.List Type classes (later) provide relations between classes.

3 Interactive Programming with ghci Lists Type expressions and run-time will evaluate Define abbreviations with let - let double n = n + n - let seven = 7 let not necessary at top level in programs loaded from files Lists - [2,3,4,9,12]: [Integer] - [] -- empty list - Must be homogenous - Functions: length, ++, :, map, rev also head, tail, but normally don t use Polymorphic Types Pattern Matching [1,2,3]:: [Integer] [ abc, def ]:: [[Char]],... []:: [a] map:: (a b) ([a] [b]) Use :t exp to get type of exp Decompose lists: - [1,2,3] = 1:(2:(3:[])) Define functions by cases using pattern matching: prod [] = 1 prod (fst:rest) = fst * (prod rest)

4 Pattern Matching Type constructors Desugared through case expressions: - head' :: [a] -> a head' [] = error "No head for empty lists" head' (x:_) = x equivalent to - head' xs = case xs of [] -> error "No head for empty lists" (x:_) -> x Tuples - (17, abc, True) : (Integer, [Char], Bool) - fst, snd defined only on pairs Records exist as well More Pattern Matching Static Typing Strongly typed via type inference (x,y) = (5 `div` 2, 5 `mod` 2) hd:tl = [1,2,3] hd:_ = [4,5,6] - _ is wildcard. - head:: [a] a tail:: [a] [a] - last [x] = x last (hd:tail) = last tail System deduces most general type, [a] -> a - Look at algorithm later

5 Static Scoping What is the answer? let x = 3" let g y = x + y" g 2" let x = 6" - g 2" What is the answer in original LISP? (define x 3)" (define (g y) (+ x y))" (g 2)" (define x 6)" - (g 2) What is the answer? let x = 3" let g y = x + y" g 2" let x = 6" - g 2 Static Scoping What is the answer in original LISP? (define x 3)" (define (g y) (+ x y))" (g 2)" (define x 6)" - (g 2) { const x = 3 { g(y) = x + y { print (g 2) const x = 6 { print (g 2) } } } } Local Declarations roots (a,b,c) = " let -- indenting is significant" disc = sqrt(b*b-4.0*a*c)" in" ((-b + disc)/(2.0*a),(-b - disc)/(2.0*a))" *Main> roots(1,5,6)" (-2.0,-3.0)" or roots' (a,b,c) = ((-b + disc)/(2.0*a), (-b - disc)/(2.0*a))" where disc = sqrt(b*b-4.0*a*c) Anonymous functions dble x = x + x abbreviates" dble = \x -> x + x

6 Defining New Types Type abbreviations - type Point = (Integer, Integer) - type Pair a = (a,a) data definitions - create new type with constructors as tags. - generative data Color = Red Green Blue See more complex examples later Type Classes Intro Specify an interface: - class Eq a where (==) :: a -> a -> Bool -- specify ops (/=) :: a -> a -> Bool x == y = not (x /= y) -- optional implementations x /= y = not (x == y) - data TrafficLight = Red Yellow Green instance Eq TrafficLight where Red == Red = True Green == Green = True Yellow == Yellow = True _ == _ = False Common Type Classes Eq, Ord, Enum, Bounded, Show, Read - See data defs pick up default if add to class: - data... deriving (Show, Eq) Can redefine: - instance Show TrafficLight where show Red = "Red light" show Yellow = "Yellow light" show Green = "Green light" More Type Classes class (Eq a) => Num a where... - instance of Num a must be Eq a Polymorphic function types can be prefixed w/ type classes - test x y = x < y has type (Ord a) => a -> a -> Bool - Can be used w/ x, y of any Ord type." More later..." - Error messages often refer to actual parameter needing to be instance of a class -- to have an operation.

7 Higher-Order Functions Functions that take function as parameter - Ex: map:: (a b) ([a] [b]) Build new control structures - listify oper identity [] = identity listify oper identity (fst:rest) = oper fst (listify oper identity rest) - sum' = listify (+) 0 mult' = listify (*) 1 and' = listify (&&) True or' = listify ( ) False Quicksort partition (pivot, []) = ([],[]) " partition (pivot, first : others) = " let " (smalls, bigs) = partition(pivot, others) " in " if first < pivot " " then (first:smalls, bigs) " " else (smalls, first:bigs)" Type is: " partition :: (Ord a) => (a, [a]) -> ([a], [a]) Quicksort qsort [] = [] " qsort [singleton] = [singleton] " qsort (first:rest) = " let " """ (smalls, bigs) = partition(first,rest) " ""in " """ qsort(smalls) ++ [first] ++ qsort(bigs)" Type is: " qsort :: (Ord t) => [t] -> [t] Quicksort - parametrically partition (pivot, []) lthan = ([],[]) " partition (pivot, first : others) lthan = " let " (smalls, bigs) = partition(pivot, others) lthan in " if (lthan first pivot) " then (first:smalls, bigs) " else (smalls, first:bigs) " partition :: " (t, [a]) -> (a -> t -> Bool) -> ([a], [a])" *Main> partition(6,[8,4,6,3])(>)"

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

CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

### Programming Languages Fall 2013

Programming Languages Fall 2013 Lecture 2: types Prof. Liang Huang huang@qc.cs.cuny.edu Recap of Lecture 1 functional programming vs. imperative programming basic Haskell syntax function definition lazy

### CSE 505. Lecture #9. October 1, Lambda Calculus. Recursion and Fixed-points. Typed Lambda Calculi. Least Fixed Point

Lambda Calculus CSE 505 Lecture #9 October 1, 2012 Expr ::= Var λ Var. Expr (Expr Expr) Key Concepts: Bound and Free Occurrences Substitution, Reduction Rules: α, β, η Confluence and Unique Normal Form

### PROGRAMMING IN HASKELL. Chapter 2 - First Steps

PROGRAMMING IN HASKELL Chapter 2 - First Steps 0 The Hugs System Hugs is an implementation of Haskell 98, and is the most widely used Haskell system; The interactive nature of Hugs makes it well suited

### 301AA - Advanced Programming [AP-2017]

301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-15: Func'onal

### CS 360: Programming Languages Lecture 12: More Haskell

CS 360: Programming Languages Lecture 12: More Haskell Geoffrey Mainland Drexel University Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia Administrivia Homework 5 due

### Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are first-class values E.g., functions

### Conversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";

Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";

### Lists. Michael P. Fourman. February 2, 2010

Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce

### Tuples. CMSC 330: Organization of Programming Languages. Examples With Tuples. Another Example

CMSC 330: Organization of Programming Languages OCaml 2 Higher Order Functions Tuples Constructed using (e1,..., en) Deconstructed using pattern matching Patterns involve parens and commas, e.g., (p1,p2,

T O Y H Advances in Programming Languages APL8: Multiparameter Type Classes, Constructor Classes Ian Stark School of Informatics The University of Edinburgh Thursday 4 February Semester 2 Week 4 E H U

About the Tutorial Haskell is a widely used purely functional language. Functional programming is based on mathematical functions. Besides Haskell, some of the other popular languages that follow Functional

### CSCE 314 Programming Languages

CSCE 314 Programming Languages Haskell 101 Dr. Hyunyoung Lee 1 Contents 1. Historical Background of Haskell 2. Lazy, Pure, and Functional Language 3. Using ghc and ghci 4. Functions 5. Haskell Scripts

Overloading, Type Classes, and Algebraic Datatypes Delivered by Michael Pellauer Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. September 28, 2006 September 28, 2006 http://www.csg.csail.mit.edu/6.827

### Type system. Type theory. Haskell type system. EDAN40: Functional Programming Types and Type Classes (revisited)

Type system EDAN40: Functional Programming Types and Type Classes (revisited) Jacek Malec Dept. of Computer Science, Lund University, Sweden April 3rd, 2017 In programming languages, a type system is a

### User-Defined Algebraic Data Types

72 Static Semantics User-Defined Types User-Defined Algebraic Data Types An algebraic data type declaration has the general form: data cx T α 1... α k = K 1 τ 11... τ 1k1... K n τ n1... τ nkn introduces

### GHCi: Getting started (1A) Young Won Lim 6/3/17

GHCi: Getting started (1A) Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

### Part I. Language Core

Part I Language Core 7 The first part of this book is a complete introduction to the core of the Objective Caml language, in particular the expression evaluation mechanism, static typing and the data

### A tour of the Haskell Prelude

A tour of the Haskell Prelude Bernie Pope 2001 1 Haskell The Haskell language was conceived during a meeting held at the 1987 Functional Programming and Computer Architecture conference (FPCA 87). At the

Processadors de Llenguatge II Functional Paradigm II Pratt A.7 Robert Harper s SML tutorial (Sec II) Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra User-Defined Types How to define the new type.

### Functional Programming TDA 452, DIT 142

Chalmers Göteborgs Universitet 2018-01-11 Examiner: Thomas Hallgren, D&IT, Answering questions at approx 15.00 (or by phone) Functional Programming TDA 452, DIT 142 2018-01-11 14.00 18.00 Samhällsbyggnad

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

CMSC 330: Organization of Programming Languages OCaml 1 Functional Programming Dialects of ML ML (Meta Language) Univ. of Edinburgh,1973 Part of a theorem proving system LCF The Logic of Computable Functions

### Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 6: Polymorphic Type Systems 1. Polymorphic

### Haskell Making Our Own Types and Typeclasses

Haskell Making Our Own Types and Typeclasses http://igm.univ-mlv.fr/~vialette/?section=teaching Stéphane Vialette LIGM, Université Paris-Est Marne-la-Vallée January 13, 2015 Making Our Own Types and Typeclasses

### Types in Programming Languages Dynamic and Static Typing, Type Inference (CTM 2.8.3, EPL* 4) Abstract Data Types (CTM 3.7) Monads (GIH** 9)

Types in Programming Languages Dynamic and Static Typing, Type Inference (CTM 2.8.3, EPL* 4) Abstract Data Types (CTM 3.7) Monads (GIH** 9) Carlos Varela Rensselaer Polytechnic Institute September 23,

### So what does studying PL buy me?

So what does studying PL buy me? Enables you to better choose the right language but isn t that decided by libraries, standards, and my boss? Yes. Chicken-and-egg. My goal: educate tomorrow s tech leaders

### Introduction to Functional Programming in Haskell 1 / 56

Introduction to Functional Programming in Haskell 1 / 56 Outline Why learn functional programming? The essence of functional programming What is a function? Equational reasoning First-order vs. higher-order

### Tentamen Functioneel Programmeren 2001 Informatica, Universiteit Utrecht Docent: Wishnu Prasetya

Tentamen Functioneel Programmeren 2001 Informatica, Universiteit Utrecht Docent: Wishnu Prasetya 04-05-2001, 09.00-12.00, Educatorium Gamma This test consists of two parts. For the first part, which is

### Abstract Types, Algebraic Types, and Type Classes

Informatics 1 Functional Programming Lectures 13 and 14 Monday 9 and Tuesday 10 November 2009 Abstract Types, Algebraic Types, and Type Classes Philip Wadler University of Edinburgh Reminders Tutorial

### Lecture 4: Higher Order Functions

Lecture 4: Higher Order Functions Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense September 26, 2017 HIGHER ORDER FUNCTIONS The order of a function

### Parallel Haskell on MultiCores and Clusters

Parallel Haskell on MultiCores and Clusters (part of Advanced Development Techniques) Hans-Wolfgang Loidl School of Mathematical and Computer Sciences Heriot-Watt University, Edinburgh (presented at the

### Data types for mcrl2

Data types for mcrl2 Aad Mathijssen April 5, 2018 We provide a syntax for the standard data types of the mcrl2 language. This syntax is intended to be a practical mix between standard mathematical notation

### Getting Started with Haskell (10 points)

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.827 Multithreaded Parallelism: Languages and Compilers Problem Set 1 Out: September 19, 2006 Due: October

### Types, Type Inference and Unification

Types, Type Inference and Unification Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Cornell CS 6110 Summary (Functional Programming) Lambda Calculus Basic ML Advanced ML: Modules, References,

### An Overview of Miranda

FROM SIGPLAN NOTICES, 21(12):158-166, December 1986. c D.A.Turner An Overview of Miranda David Turner Computing Laboratory University of Kent Canterbury CT2 7NF ENGLAND Miranda is an advanced functional

### Thoughts on Assignment 4 Haskell: Flow of Control

Thoughts on Assignment 4 Haskell: Flow of Control CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 27, 2017 Glenn G. Chappell Department of Computer

Functional Programming Language Haskell Mohammed Aslam CIS 24 Prof. Kopec Presentation: 03 Date: 05/05/2003 Haskell is a general purpose, purely functional programming language named after the logician

### Programming with Math and Logic

.. Programming with Math and Logic an invitation to functional programming Ed Morehouse Wesleyan University The Plan why fp? terms types interfaces The What and Why of Functional Programming Computing

### Basic types and definitions. Chapter 3 of Thompson

Basic types and definitions Chapter 3 of Thompson Booleans [named after logician George Boole] Boolean values True and False are the result of tests are two numbers equal is one smaller than the other

### Modules and Representation Invariants

Modules and Representation Invariants COS 326 Andrew W. Appel Princeton University slides copyright 2013-2015 David Walker and Andrew W. Appel In previous classes: Reasoning about individual OCaml expressions.

### More Lambda Calculus and Intro to Type Systems

More Lambda Calculus and Intro to Type Systems Plan Heavy Class Participation Thus, wake up! Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems Overview Static, Dyamic

### Intro to Haskell Notes: Part 1

Intro to Haskell Notes: Part 1 Adrian Brasoveanu July 1, 2013 Contents 1 Comments 2 2 Simple arithmetic 2 3 Boolean operators 2 4 Testing for equality 3 5 No covert type conversion 3 6 Functions 4 6.1

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

CS 3110 Lecture 6: Map and Fold Prof. Clarkson Fall 2014 Today s music: Selections from the soundtrack to 2001: A Space Odyssey Review Features so far: variables, operators, let expressions, if expressions,

### CS558 Programming Languages

CS558 Programming Languages Fall 2016 Lecture 6a Andrew Tolmach Portland State University 1994-2016 Functional Programming An alternative paradigm to imperative programming First-class functions Emphasis

### CSC324 Functional Programming Typing, Exceptions in ML

CSC324 Functional Programming Typing, Exceptions in ML Afsaneh Fazly 1 Winter 2013 1 with many thanks to Anya Tafliovich, Gerald Penn, Sheila McIlraith, Wael Aboelsaddat, Tony Bonner, Eric Joanis, Suzanne

### Programming in Haskell Aug-Nov 2015

Programming in Haskell Aug-Nov 2015 LECTURE 14 OCTOBER 1, 2015 S P SURESH CHENNAI MATHEMATICAL INSTITUTE Enumerated data types The data keyword is used to define new types data Bool = False True data Day

CIS552: Advanced Programming Handout 8 What is a Parser? A parser is a program that analyzes a piece of text to deine its structure (and, typically, returns a tree representing this structure). The World

### Principles of Programming Languages, 3

Principles of Programming Languages, 3 Matteo Pradella May 2015 Matteo Pradella Principles of Programming Languages, 3 May 2015 1 / 94 1 Introduction on purity and evaluation 2 Haskell Matteo Pradella

### Lecture 2: List algorithms using recursion and list comprehensions

Lecture 2: List algorithms using recursion and list comprehensions Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense September 12, 2017 Expressions, patterns

### CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages Syntax R. Sekar 1 / 63 Topics 1. Introduction 2. Basics 3. Functions 4. Data Structures 5. Overview 6. OCAML Performance 2 / 63 Section 1 Introduction 3 / 63

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

Recursion Lecture 6: More Lambda Calculus Programming CSC 131! Fall, 2014!! Kim Bruce Recursive definitions are handy! - fact = λn. cond (iszero n) 1 (Mult n (fact (Pred n)))! - Not a legal definition

### CSc 520 Principles of Programming Languages

CSc 520 Principles of Programming Languages 16 : Types Polymorphism Christian Collberg collberg+520@gmail.com Department of Computer Science University of Arizona Copyright c 2008 Christian Collberg [1]

### Polymorphism Overview (1A) Young Won Lim 2/20/18

Polymorphism Overview (1A) Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

### Why OCaml? Introduction to Objective Caml. Features of OCaml. Applications written in OCaml. Stefan Wehr

Motivation Introduction to Objective Caml Why OCaml? Stefan Wehr University of Freiburg. October 30, 2006 Motivation Simple Expressions and Types I/O and Compilation Resources Convenient encoding of tree

### Documentation for the Idris Language. Version 0.99

Documentation for the Idris Language Version 0.99 Contents 1 The Idris Tutorial 2 2 Frequently Asked Questions 61 3 The Effects Tutorial 66 4 Theorem Proving 98 5 Language Reference 109 6 Tutorials on

### Introduction to Objective Caml

Introduction to Objective Caml Stefan Wehr University of Freiburg. October 30, 2006 Motivation Simple Expressions and Types Functions Simple Pattern Matching Compound Datatypes I/O and Compilation Resources

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

CS 3110 Lecture 6: Map and Fold Prof. Clarkson Spring 2015 Today s music: Selections from the soundtrack to 2001: A Space Odyssey Review Course so far: Syntax and semantics of (most of) OCaml Today: No

### A Brief Introduction to Standard ML

A Brief Introduction to Standard ML Specification and Verification with Higher-Order Logic Arnd Poetzsch-Heffter (Slides by Jens Brandt) Software Technology Group Fachbereich Informatik Technische Universität

### GHCi: Getting started (1A) Young Won Lim 5/26/17

GHCi: Getting started (1A) Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

Programming Paradigms, Fall 06 Multiple Choice Exam January 29, 2007, 10:00 11:15 ID Name Each of the following questions has exactly one correct answer. For each question, you may select one or more answers

### Data Types The ML Type System

7 Data Types 7.2.4 The ML Type System The following is an ML version of the tail-recursive Fibonacci function introduced Fibonacci function in ML in Section 6.6.1: EXAMPLE 7.96 1. fun fib (n) = 2. let

About the Tutorial Haskell is a widely used purely functional language. Functional programming is based on mathematical functions. Besides Haskell, some of the other popular languages that follow Functional

### Type Checking and Type Inference

Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled

### Documentation for the Idris Language. Version 1.0

Documentation for the Idris Language Version 1.0 Contents 1 The Idris Tutorial 2 2 Frequently Asked Questions 62 3 Implementing State-aware Systems in Idris: The ST Tutorial 67 4 The Effects Tutorial 102

### Haskell-Tutorial. Damir Medak Gerhard Navratil. Institute for Geoinformation Technical University Vienna. February 2003

Haskell-Tutorial Damir Medak Gerhard Navratil Institute for Geoinformation Technical University Vienna February 2003 There are numerous books on functional programming. These books are good, but usually

Advanced features of Functional Programming (Haskell) Polymorphism and overloading January 10, 2017 Monomorphic and polymorphic types A (data) type specifies a set of values. Examples: Bool: the type of

### Haskell A Wild Ride. Abstract. 1 Safety Precautions. Sven Moritz Hallberg

Haskell A Wild Ride Sven Moritz Hallberg 21st. Chaos Communication Congress Berlin, December 27th 29th 2004 Abstract The Haskell programming language is a comparatively young purely functional

### Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda

Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered

### Informatics 1 Functional Programming Lecture 12. Data Abstraction. Don Sannella University of Edinburgh

Informatics 1 Functional Programming Lecture 12 Data Abstraction Don Sannella University of Edinburgh Part I Sets as lists without abstraction We will look again at our four ways of implementing sets.

### CSc 520. Principles of Programming Languages 25: Types Introduction

CSc 520 Principles of Programming Languages 25: Types Introduction Christian Collberg Department of Computer Science University of Arizona collberg@cs.arizona.edu Copyright c 2005 Christian Collberg April

### What s different about Factor?

Harshal Lehri What s different about Factor? Factor is a concatenative programming language - A program can be viewed as a series of functions applied on data Factor is a stack oriented program - Data

CSci 450: Org. of Programming Languages Overloading and Type Classes H. Conrad Cunningham 27 October 2017 (after class) Contents 9 Overloading and Type Classes 1 9.1 Chapter Introduction.........................

### 7. Introduction to Denotational Semantics. Oscar Nierstrasz

7. Introduction to Denotational Semantics Oscar Nierstrasz Roadmap > Syntax and Semantics > Semantics of Expressions > Semantics of Assignment > Other Issues References > D. A. Schmidt, Denotational Semantics,

### An introduction to C++ template programming

An introduction to C++ template programming Hayo Thielecke University of Birmingham http://www.cs.bham.ac.uk/~hxt March 2015 Templates and parametric polymorphism Template parameters Member functions of

### FUNCTIONAL AND LOGIC PROGRAMS

FUNCTIONAL AND LOGIC PROGRAMS Contents Language Specific Compilation Context Handling Identification Scope Overloading Imported Scope Type Checking Type table Type equivalence Coercions Casts and conversions

### Haskell: yet another Functional Language. Distributed and Parallel Technology

Distributed and Parallel Technology Introducing Haskell Hans-Wolfgang Loidl http://www.macs.hw.ac.uk/~hwloidl School of Mathematical and Computer Sciences Heriot-Watt University, Edinburgh Haskell: yet

### Shell CSCE 314 TAMU. Functions continued

1 CSCE 314: Programming Languages Dr. Dylan Shell Functions continued 2 Outline Defining Functions List Comprehensions Recursion 3 A Function without Recursion Many functions can naturally be defined in

### Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

### More Lambda Calculus and Intro to Type Systems

#1 More Lambda Calculus and Intro to Type Systems #2 Plan Heavy Class Participation Thus, wake up! (not actually kidding) Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems

### Tree Oriented Programming. Jeroen Fokker

Tree Oriented Programming Jeroen Fokker Tree oriented programming Many problems are like: Input text transform process unparse Output text Tree oriented programming Many problems are like: Input text parse

### Tree Equality: The Problem

Recall the tree data type we defined: Tree Equality: The Problem data LTree a = LLeaf a LBranch (LTree a) (LTree a) Suppose we want to write a function that determines if two trees are equal: treeeq (LLeaf

### OCaml Language Choices CMSC 330: Organization of Programming Languages

OCaml Language Choices CMSC 330: Organization of Programming Languages! Implicit or explicit declarations?! Explicit variables must be introduced with let before use! But you don t need to specify types

### Computing Fundamentals 2 Introduction to CafeOBJ

Computing Fundamentals 2 Introduction to CafeOBJ Lecturer: Patrick Browne Lecture Room: K408 Lab Room: A308 Based on work by: Nakamura Masaki, João Pascoal Faria, Prof. Heinrich Hußmann. See notes on slides

### Monad Background (3A) Young Won Lim 11/18/17

Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published

### How does ML deal with +?

How does ML deal with +? Moscow ML version 2.00 (June 2000) - op +; > val it = fn : int * int -> int - 1 + 1; > val it = 2 : int - 1.0 + 1.0; > val it = 2.0 : real - false + false;! Overloaded + cannot

### SMURF Language Reference Manual Serial MUsic Represented as Functions

SMURF Language Reference Manual Serial MUsic Represented as Functions Richard Townsend, Lianne Lairmore, Lindsay Neubauer, Van Bui, Kuangya Zhai {rt2515, lel2143, lan2135, vb2363, kz2219}@columbia.edu

### Intro. Scheme Basics. scm> 5 5. scm>

Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

### CIS 194: Homework 4. Due Wednesday, February 18, What is a Number?

CIS 194: Homework 4 Due Wednesday, February 18, 2015 What is a Number? This may sound like a deep, philosophical question, but the Haskell type system gives us a simple way to answer it. A number is any

### Homework 1: Functional Programming, Haskell

Com S 541 Programming Languages 1 September 25, 2005 Homework 1: Functional Programming, Haskell Due: problems 1 and 3, Thursday, September 1, 2005; problems 4-9, Thursday, September 15, 2005; remaining

### HANDLING NONLOCAL REFERENCES

SYMBOL TABLE A symbol table is a data structure kept by a translator that allows it to keep track of each declared name and its binding. Assume for now that each name is unique within its local scope.

### POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public

### CS 457/557: Functional Languages

CS 457/557: Functional Languages From Trees to Type Classes Mark P Jones Portland State University 1 Trees:! " There are many kinds of tree data structure.! " For example: data BinTree a = Leaf a BinTree

### 9/28/09. Kathleen Fisher. Question: Interesting answer in Algol:

cs4 Lisp Algol 60 Algol 68 Kathleen Fisher Pascal C Smalltalk Reading: Concepts in Programming Languages Chapter 5 except 5.4.5 Real World Haskell, Chapter 0 and Chapter (http://book.realworldhaskell.org/)

### Key Differences Between Python and Java

Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.

Advanced Functional Programming Tim Sheard Polymorphism Hindley-Milner Polymorphism Rank 2 polymorphism Tim Sheard 1 Polymorphism A function is polymorphic if it can work on any kind of argument. f x =

Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short