Comp 205: Comparative Programming Languages Functional Programming Languages: Haskell Lecture notes, exercises, etc., can be found at: www.csc.liv.ac.uk/~grant/Teaching/COMP205/

Slides:



Advertisements
Similar presentations
Engineering EG167C - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review.
Advertisements

Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
1 Demo Reading Assignments Important terms & concepts Fundamental Data Types Identifier Naming Arithmetic Operations Sample Programs CSE Lecture.
Math 191: Mathematics and Geometry for Designers Lecture Notes Based on The Book Mathematics in Our World by Allan G. Bluman.
Operators, Functions and Modules1 Operators and Functions.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Comp 205: Comparative Programming Languages User-Defined Types Enumerated types Parameterised types Recursive types Lecture notes, exercises, etc., can.
1 Data types, operations, and expressions Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions.
Lecture 4 Types & Expressions COMP1681 / SE15 Introduction to Programming.
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
Comp 205: Comparative Programming Languages Functional Programming Languages: More Haskell Lecture notes, exercises, etc., can be found at:
Comp 205: Comparative Programming Languages Imperative Programming Languages Functional Programming Languages Semantics Other Paradigms Lecture notes,
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
Comp 205: Comparative Programming Languages Functional Programming Languages: More Lists Recursive definitions List comprehensions Lecture notes, exercises,
String Escape Sequences
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Introduction to Programming (in C++) Data types and visibility Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. Computer Science, UPC.
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
2440: 211 Interactive Web Programming Expressions & Operators.
Operators, Functions and Modules1 Pattern Matching & Recursion.
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.
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Building Java Programs Primitive Data and Definite Loops.
Overview of the Haskell 98 Programming Language
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
CSI 3125, Preliminaries, page 1 Data Type, Variables.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
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.
C Part 1 Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens A History Lesson Development of language by Dennis Ritchie at Bell.
Programming Fundamentals. Summary of Previous Lectures Phases of C++ Environment Data Types cin and cout.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
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.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
An introduction to functional programming using Haskell CENG242 –Recitation 1.
A Sample Program #include using namespace std; int main(void) { cout
Georgia Institute of Technology Introduction to Java, and DrJava part 1 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Functional Programming Lecture 1 - Introduction Professor Muffy Calder.
CompSci 230 S Programming Techniques
INC 161 , CPE 100 Computer Programming
A lightening tour in 45 minutes
Comp 205: Comparative Programming Languages
Adding and Subtracting Integers is like …
Haskell.
CSE 3302 Programming Languages
IDENTIFIERS CSC 111.
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
Introduction to Java, and DrJava part 1
Introduction to Variables, Algebraic Expressions, and Equations
Python Primer 1: Types and Operators
Introduction to Java, and DrJava
Declarative Computation Model Single assignment store (VRH 2
PROGRAMMING IN HASKELL
Introduction to Java, and DrJava
Introduction to Java, and DrJava part 1
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
Primitive Data Types and Operators
Presentation transcript:

Comp 205: Comparative Programming Languages Functional Programming Languages: Haskell Lecture notes, exercises, etc., can be found at:

An Introduction to Haskell The interpreter Types Expressions Functions Evaluation

Starting Hugs $ which hugs /usr/bin/hugs $ hugs... Reading file ".../Prelude.hs" Hugs session for: /usr/share/hugs/lib/Prelude.hs Type :? for help Prelude>

Interpreting What? The interpreter does two things: Evaluate expressions Evaluate commands, e.g. :quit quit :load load a file :r redo the last load command

Interpreting Expressions Prelude>

Interpreting Expressions Prelude> Prelude>

Interpreting Expressions Prelude> Prelude> < True Prelude>

Interpreting Expressions Prelude> Prelude> < True Prelude> 3 == sqrt True Prelude>

Interpreting Expressions Prelude> Prelude> < True Prelude> 3 == sqrt True Prelude> 3 / Prelude>

Interpreting Expressions Prelude> Prelude> < True Prelude> 3 == sqrt True Prelude> 3 / Prelude> 4 / Prelude>

Integer Unbounded integer numbers Int 32-bit integer numbers Rational Unbounded rational numbers Float, Double Single- and double-precision floating point numbers Bool Boolean values Char Characters, e.g., 'a' Types

Expressions In Haskell, expressions are built from: constants operators function applications (brackets)

Expressions Constants are literal denotations, e.g.: True 'a' "hello" [1,2,4,9] Function application uses prefix notation: even 47 twice (-2)

. function composition *, /, ^ multiply, divide, power *, - addition, subtraction :, ++ add to list, concatenate ==,/=,<=,... equals, unequal, comparison && logical and || logical or Operators

Definitions -- approximation to mathematical pi pie = Programmers can define constants and functions Definitions must be contained in a file (e.g., arithmetic.hs ) A constant simply introduces an alias for a value:

Functions -- compute circumference of a circle -- given its radius circumference r = 2 * pie * r -- area of a circle area rad = pie * rad^2 Function definitions have the form: =

The Offside Rule circumference r = 2 * pie * r area r = pie * r * r bad x = area x + circumference x -- offside! Indentation determines where a definition ends:

Declaring Types circumference :: Float -> Float circumference r = 2 * pie * r area :: Double -> Double area r = pie * r ^ 2 Function definitions can include type declarations

Hugging Files Prelude> :l arithmetic Main> area Main>

Pattern-Matching #1 -- factorial of a number fact :: Integer -> Integer fact 0 = 1 fact n = fact (n-1) * n Functions can be defined using more than one equation:

Summary Key topics: Expressions Types function definitions pattern-matching Next: More Haskell