Functional Programming and Haskell

Slides:



Advertisements
Similar presentations
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 14 Functional Programming Languages - The design of the imperative languages is based directly.
Advertisements

1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
CS 355 – Programming Languages
Programming Languages Structure
Programming Language Theory Leif Grönqvist The national Graduate School of Language Technology (GSLT) MSI.
Comp 205: Comparative Programming Languages Imperative Programming Languages Functional Programming Languages Semantics Other Paradigms Lecture notes,
Dr. Muhammed Al-Mulhem ICS An Introduction to Functional Programming.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
0 PROGRAMMING IN HASKELL An Introduction Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
Haskell. 2 GHC and HUGS Haskell 98 is the current version of Haskell GHC (Glasgow Haskell Compiler, version 7.4.1) is the version of Haskell I am using.
0 REVIEW OF HASKELL A lightening tour in 45 minutes.
1 Programming Language History and Evolution In Text: Chapter 2.
1 COMP313A Functional Programming (1). 2 Main Differences with Imperative Languages Say more about what is computed as opposed to how Pure functional.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
Chapter Fifteen: Functional Programming Languages Lesson 12.
Lee CSCE 314 TAMU 1 CSCE 314 Programming Languages Haskell 101 Dr. Hyunyoung Lee.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
1-1 An Introduction to Functional Programming Sept
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
Functional Programming Part 1. Organization of Programming Languages-Cheng Big Picture u What we’ve learned so far: Imperative Programming Languages 
Haskell Basics CSCE 314 Spring CSCE 314 – Programming Studio Using GHC and GHCi Log in to unix.cse.tamu.edu (or some other server) From a shell.
Copyright © 2009 Elsevier Chapter 10 :: Functional Languages Programming Language Pragmatics Michael L. Scott.
Haskell Introduction CSCE 314 Spring CSCE 314 – Programming Studio Historical Background 1930s: Alonzo Church develops the lambda calculus, a simple.
Haskell. GHC and HUGS Haskell 98 is the current version of Haskell GHC (Glasgow Haskell Compiler, version 7.4.1) is the version of Haskell I am using.
History of Lisp And Functional Programming Languages Scotty Smith.
Erik Meijer FP101x - Functional Programming Programming in Haskell - Introduction.
1 PROGRAMMING IN HASKELL An Introduction Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
Language Paradigms CS655.
Functional Programming Lecture 1 - Introduction Professor Muffy Calder.
Functional Programming
Programming Languages winter term 2010/11
Programming Language History and Evolution
Programming Languages 2nd edition Tucker and Noonan
Functional Programming
Functional Programming Languages
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
What is a Functional Language?
Functional Programming
Midterm recap Total was 80 points Distribution range
CS 3304 Comparative Languages
dr Robert Kowalczyk WMiI UŁ
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Expressions and Assignment
Chapter 11 :: Functional Languages
Representation, Syntax, Paradigms, Types
A lightening tour in 45 minutes
CS 326 Programming Languages, Concepts and Implementation
Comp 205: Comparative Programming Languages
Haskell.
CSE 3302 Programming Languages
Programming Language History and Evolution
Fundamentals of Functional Programming Languages
Programming Language Design
FP Foundations, Scheme In Text: Chapter 14.
Functional Programming Languages
Representation, Syntax, Paradigms, Types
Programming Languages 2nd edition Tucker and Noonan
Representation, Syntax, Paradigms, Types
PROGRAMMING IN HASKELL
Overview of Programming Paradigms
Representation, Syntax, Paradigms, Types
CSCE 314: Programming Languages Dr. Dylan Shell
Functional Programming and Haskell
PROGRAMMING IN HASKELL
Chapter 15 Functional Programming 6/1/2019.
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
Presentation transcript:

Functional Programming and Haskell Computer Science 312 Functional Programming and Haskell 1

The “Software Crisis” Improvements in processing speed and memory capacity (Moore’s Law) allow applications to grow in size and complexity As software grows in size and complexity, it becomes more challenging to debug, verify, and maintain A crisis point was reached in the mid-1970s

A Primary Culprit: Side Effects Much of the complexity of software depends on the fact that programs change the state of the computer with time The number of interactions between states can grow exponentially with the number of states Many of these interactions, also called aide effects, can lead to errors

Early Remedies: Restrict Interactions Modularize software, to support information hiding, security, and independent, plug-and-play testing and development (Modula, Ada) Factor code into objects and classes, with data encapsulation, polymorphism, and inheritance (Smalltalk, C++, later Java, Python) State survives, still challenging to detect all errors

Example Changes of State A method can change the states of its parameters A method can change the state of the current object’s instance variables, either directly or by calling other methods that do so A method can modify class variables, module variables, or any others that are in scope A method can perform I/O (files, interactive, network)

Another Remedy: Drop the States! Think of computation as a set of transformations of data values into other data values, rather than as a sequence of changes of state Each transformation guarantees the same results for the same data values One constructs a set of transformations just like one constructs a proof – verification built in!

Functional Programming A program consists of a set of cooperating functions Each function is pure, guaranteeing the same results for the same data values There is just single assignment, for parameters and for temporary variables No side effects!

Historical Precedents Haskell Curry – combinatorial logic (1930) Alonzo Church – recursive lambda calculus (1940) John McCarthy – the first LISP system (1959) John Backus – ACM Turing Award lecture (1977) First purely functional languages – ML, Miranda, Haskell (1970s and 80s)

Haskell Created by a committee in 1987, to collect the best features of existing functional languages First definition released to the public in 1990 Static, compile-time type checking Iteration by means of recursion Functions as first-class data, higher-order functions

Haskell Pattern matching simplifies control Lazy evaluation of function arguments Compiles to native code Strictness is augmented with “monads” for stateful computations, such as I/O and generating random numbers

Obtaining Haskell Download the Haskell Platform and documentation from https://www.haskell.org/ Use your favorite editor to create programs, or a plugin for an IDE such as Eclipse (Atom and Editra are good) Tools include the GHC (Glasgow Haskell Compiler) and the GHCI (Glasgow Haskell Compiler Interactive), as well as many others for creating documentation, libraries, etc.

Haskell Pragmatics Expressions can be evaluated interactively in an interpreter (the GHCI) Programs consist of modules of function definitions, which must be saved in files, compiled, and imported for use Programs can be compiled as standalone apps for release

Firing up the ghci Shell The Haskell Prelude is the default standard module in the GHCI As does Python’s IDLE, the GHCI provides a REPL (read-eval-print loop)

Numbers, Arithmetic, Comparisons Prelude> 53 -- Syntax: <expression> 53 Prelude> 3.14 3.14 Prelude> 3 + 4 * 2 11 Prelude> 3 == 4 False Prelude> 3 <= 4 True Prelude> 3 /= 4

Numbers and Function Calls Prelude> sqrt 2 1.4142135623730951 Prelude> mod 3 2 --Prefix notation, no parentheses 1 Prelude> abs -2 eError: • Non type-variable argument in the constraint: Num (a -> a) Prelude> :type abs abs :: Num a => a -> a Prelude> abs (-2) 2 Prelude> 3 / 2 1.5 Prelude> 3 `div` 2

Special Interpreter Commands

Simple data types Variables and assignment Simple function definitions For next time Simple data types Variables and assignment Simple function definitions