Haskell. greg, dbtucker

Size: px
Start display at page:

Download "Haskell. greg, dbtucker"

Transcription

1 Haskell greg, dbtucker In these lectures, we will explore the Haskell programming language. We will use the Glasgow Haskell Compiler s interactive environment (GHCi), which is available as /u/greg/bin/ghci on the department s network of Linux workstations. There is also a slightly older version available, which you will get if you simply run ghci. We run GHCi in a terminal and, after some start-up messages, it gives us a prompt 1 : Prelude> The prompt is similar to the one in DrScheme s Interactions Window. If we enter an expression, GHC evaluates it and prints the result. For example: Prelude> Prelude> To indicate function application in Haskell, we simply juxtapose the function and its arguments. In many cases, this looks similar to Scheme s syntax for function application: Prelude> (mod 7 4) Prelude> (not False) One important difference from Scheme is that parentheses in and of themselves do not indicate function application. Rather, they specify grouping of operations and can safely be added or omitted is many situations. For example, compare the following with the above: Prelude> mod 7 4 Prelude> (mod 7) ((4)) Prelude> not False Prelude> (not) False However, the following is an error, although the message we get from GHC is confusing and uninformative: Prelude> mod (7 4) Another important feature of Haskell is that it uses infix notation for operators. For example: 1 Haskell comes with a collection of built-in functions and datatypes called the Standard Prelude. This is analogous to the standard libraries of other programming languages, such as C or Java. The word Prelude in the prompt indicates that the definitions from the Prelude are visible. 1

2 Prelude> Prelude> 2 * Prelude> 2 + * 5 17 Prelude> 2 * < + 5 Haskell distinguishes between functions with alphanumeric names, such as not and or, and functions (operators) with symbolic names, such as +. By default, the former use prefix notation, while the latter use infix. However, the difference is superficial; both are really just functions. We can use ordinary functions as infix operators by enclosing them in backquotes, and we can refer to symbolic operators as ordinary functions by enclosing them in parentheses. For example: Prelude> 7 mod 4 Prelude> (<) ((*) 2 ) ((+) 5) The first type of transformation can make code easier to read, while the second is often useful when we need to pass an operator as an argument to a higher-order function (e.g., a comparator for a sorting function). We have seen two types of primitive data so far: integers (Integer) and booleans (Bool). Another simple datatype is the character (Char). Character values are denoted by enclosing the corresponding letter, digit, or control code in single quotes: Prelude> a -- the letter a a Prelude> -- the digit Prelude> \n -- newline \n } The predefined types and functions in Haskell are useful, but we will soon want to create our own. For example, let us try to write a function that converts a numeric grade to a letter grade. Unlike DrScheme, GHCi does not provide program editing capabilities, so we will write our definitions in an external editor. (X)Emacs works well, and there is a Haskell Mode, along with tools for other editors, at To activate Haskell mode, we give our source file the extension.hs. Let s call our file Examples.hs and, at the top, just to make GHC happy, we ll type: module Examples where Now we can write a contract for our function. We will call it scoretoletter and, since it is a function from integers to characters, its type is Integer Char. The symbol :: means has type, and (a b) is the type of a function that maps values of type a to values of type b. Note that type declarations in Haskell are more than just comments, and a type-checker makes sure they are correct. We next write the actual function definition, which begins with the name of the function followed by formal names for its argument(s): 2

3 In Scheme, this function would be an ideal candidate for a cond statement. Unfortunately, Haskell does not provide an exact analog for cond, but there is another construct, called a guard, that is appropriate for situations like this. A guard consists of a vertical bar ( ), read where, followed by a boolean expression, an equal sign (=), and an expression. For example, to define the case where the score is at least 90, we say: n >= 90 = A The other cases are similar: n >= 90 = A n >= 80 = B n >= 70 = C otherwise = F The name otherwise simply means, like Scheme s else. Note that, as in a cond, order matters. The conditions are tested as they appear, and the first value selects the result. However, one important difference between guards and conds is that guards can only be used at the outermost level of the definition of a named function that is, they cannot be nested inside other syntax. To make GHCi load the definitions from this file, we type: Prelude> :load Examples.hs Compiling Examples ( Examples.hs, interpreted ) Ok, modules loaded: Examples. Note that the prompt has changed to indicate that the file has been loaded. Now we can test our function: *Examples> scoretoletter 9 A *Examples> scoretoletter 87 B *Examples> scoretoletter 79 C *Examples> scoretoletter 44 F If we want to modify this function, say to make the grading system more lenient, we simply change part of the definition in the source file: n >= 90 = A n >= 80 = B n >= 60 = C otherwise = F To update the definition in GHCi, we can use the :reload command. *Examples> :reload Compiling Examples ( Examples.hs, interpreted ) Ok, modules loaded: Examples.

4 (These commands also have short forms we can use :l in place of :load and :r instead of :reload.) If we could only perform computations on primitive datatypes, we would not be able to do much of interest. So, Haskell naturally provides ways of constructing more complex types of data. Lists, for example, can maintain arbitrary numbers of a given type of data. The simplest list we can construct is the empty list, denoted by []. We construct larger lists with the cons operator, written :, which takes an element of some type ( first ) and a list of that same type ( rest ), returning a list containing the new element followed by all the elements in the original list. *Examples> (1:[]) [1] *Examples> (1:2::[]) [1,2,] GHCi uses an abbreviated notation to display lists. We can also use the same syntax to construct lists (somewhat like in Scheme). *Examples> [1,2,,4,5] [1,2,,4,5] *Examples> 1:2:[,4,5] [1,2,,4,5] The Prelude defines many common list-processing functions: *Examples> filter odd [1,2,,4,5] [1,,5] *Examples> map succ [1,2,,4,5] [2,,4,5,6] *Examples> sum [1,2,,4,5] 15 *Examples> product [1,2,,4,5] 120 GHCi uses a different notation to display lists of characters, which are also called Strings. *Examples> [ a, b, c, d, e ] "abcde" *Examples> map scoretoletter [74, 9, 85, 7] "CABF" We write functions over lists by using constructor pattern matching. Since there are two list constructors ([] and :), list functions typically have two cases. As a simple example, let us write a function to compute the length of a list of integers. len :: [Integer] -> Integer len [] = 0 len (x:xs) = 1 + len xs This definition states that the length of an empty list is 0, and the length of a constructed list is one more than the length of the rest it. Since length never actually inspects the elements of the list (and hence doesn t need to name them), we can use an anonymous pattern ( ) to simplify the second part of the definition: len (_:xs) = 1 + len xs Now let s try to write a function that appends two integer lists. append :: [Integer] -> [Integer] -> [Integer]. 4

5 The type of append may look a bit strange. In Scheme, we usually write only one arrow in our types. However, in Haskell, we will see that there is an arrow for each argument. The reason for this is that Haskell makes use of an idiom called currying. ML programmers should be familiar with this idea. The idea is that any -ary function can be viewed as a unary function that returns an -ary function. We have seen that we can curry functions in Scheme with lambda. Haskell automatically does it everywhere. append :: [Integer] -> [Integer] -> [Integer] append [] l = l append (x:xs) l = x : append xs l *Examples> append [1, 2, ] [4, 5, 6] [1,2,,4,5,6] Because of currying, we can partially instantiate append. *Examples> map (append [1, 2]) [[, 4], [4, 8], [, 6, 12]] [[1,2,,4],[1,2,4,8],[1,2,,6,12]] Lists are useful for maintaining variably-sized, ordered collections of values of a single type. Suppose, instead, that we want to maintain a fixed-sized collection of values of different types. In Scheme, we would create a structure to do this. Haskell, however, conveniently provides a family of anonymous types, tuples. A natural use of tuples is to represent bindings in an environment: type Binding = (String, Value) type Env = [Binding] lookup :: String -> Env -> Value lookup _ [] = undefined lookup want ((name, val) : rest) (want == name) = val otherwise = lookup want rest mtsub = [] asub name val rest = (name, val) : rest We will also want ways of defining datatypes in the style we ve been using in class. Haskell provides a similar mechanism to Scheme s: data Expr = NumE Integer BinOpE Expr (Integer -> Integer -> Integer) Expr As with lists and tuples, we use pattern-matching to write functions over user-defined types. eval :: Expr -> Integer eval (NumE n) = n eval (BinOpE lhs op rhs) = eval lhs op eval rhs While we have been writing types for all of our definitions, Haskell s type checker is actually powerful enough to infer types for us. To see this, we can remove the type annotation from our evaluator and reload it. The :type command (abbreviated :t) will show us just the type of an expression without evaluating. *Examples> :r... *Examples> :type eval Expr -> Integer 5

6 In addition, there are many instances in Haskell where values (including functions) can have many types. These values are parameterized over other types, and we say that they are polymorphic. For example, the empty list can have type [a] for any type a. Prelude> :type [] forall a. [a] Likewise, many functions are also polymorphic, and polymorphism can involve multiple type variables. Prelude> :type id forall a. a -> a Prelude> :type map forall a b. (a -> b) -> [a] -> [b] Prelude> :type filter forall a. (a -> Bool) -> [a] -> [a] Prelude> :type zipwith forall a b c. (a -> b -> c) -> [a] -> [b] -> [c] What is perhaps more striking is that Haskell s type system can infer polymorphic types. For example, if we remove the type annotations from the list functions we wrote earlier, Haskell will infer more general types than what we originally ascribed to them: *Examples> :type len forall a. [a] -> Int *Examples> len "abcd" 4 *Examples> len [1, 2, ] *Examples> :type append forall a. [a] -> [a] -> [a] *Examples> append "abc" "def" "abcdef" 6

Chapter 7: Functional Programming Languages

Chapter 7: Functional Programming Languages Chapter 7: Functional Programming Languages Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Fun: a language

More information

Chapter 15 Functional Programming Languages

Chapter 15 Functional Programming Languages Chapter 15 Functional Programming Languages Introduction - The design of the imperative languages is based directly on the von Neumann architecture Efficiency (at least at first) is the primary concern,

More information

Type Classes with Functional Dependencies

Type Classes with Functional Dependencies Appears in Proceedings of the 9th European Symposium on Programming, ESOP 2000, Berlin, Germany, March 2000, Springer-Verlag LNCS 1782. Type Classes with Functional Dependencies Mark P. Jones Department

More information

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

The Clean programming language. Group 25, Jingui Li, Daren Tuzi The Clean programming language Group 25, Jingui Li, Daren Tuzi The Clean programming language Overview The Clean programming language first appeared in 1987 and is still being further developed. It was

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

Functional Programming

Functional Programming FP 2005 1.1 3 Functional Programming WOLFRAM KAHL kahl@mcmaster.ca Department of Computing and Software McMaster University FP 2005 1.2 4 What Kinds of Programming Languages are There? Imperative telling

More information

ML for the Working Programmer

ML for the Working Programmer ML for the Working Programmer 2nd edition Lawrence C. Paulson University of Cambridge CAMBRIDGE UNIVERSITY PRESS CONTENTS Preface to the Second Edition Preface xiii xv 1 Standard ML 1 Functional Programming

More information

Introduction to Data Structures

Introduction to Data Structures Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate

More information

Anatomy of Programming Languages. William R. Cook

Anatomy of Programming Languages. William R. Cook Anatomy of Programming Languages William R. Cook Copyright (C) 2013 2 Chapter 1 Preliminaries Preface What? This document is a series of notes about programming languages, originally written for students

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

How To Program In Scheme (Prolog)

How To Program In Scheme (Prolog) The current topic: Scheme! Introduction! Object-oriented programming: Python Functional programming: Scheme! Introduction Next up: Numeric operators, REPL, quotes, functions, conditionals Types and values

More information

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example Overview Elements of Programming Languages Lecture 12: Object-oriented functional programming James Cheney University of Edinburgh November 6, 2015 We ve now covered: basics of functional and imperative

More information

The design recipe. Programs as communication. Some goals for software design. Readings: HtDP, sections 1-5

The design recipe. Programs as communication. Some goals for software design. Readings: HtDP, sections 1-5 The design recipe Readings: HtDP, sections 1-5 (ordering of topics is different in lectures, different examples will be used) Survival and Style Guides CS 135 Winter 2016 02: The design recipe 1 Programs

More information

Python Lists and Loops

Python Lists and Loops WEEK THREE Python Lists and Loops You ve made it to Week 3, well done! Most programs need to keep track of a list (or collection) of things (e.g. names) at one time or another, and this week we ll show

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Regular Expressions and Automata using Haskell

Regular Expressions and Automata using Haskell Regular Expressions and Automata using Haskell Simon Thompson Computing Laboratory University of Kent at Canterbury January 2000 Contents 1 Introduction 2 2 Regular Expressions 2 3 Matching regular expressions

More information

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014! Programming Language Rankings Lecture 15: Type Inference, polymorphism & Type Classes CSC 131 Fall, 2014 Kim Bruce Top Combined Tiobe Index 1. JavaScript (+1) 2. Java (-1) 3. PHP 4. C# (+2) 5. Python (-1)

More information

Semantic Analysis: Types and Type Checking

Semantic Analysis: Types and Type Checking Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors

More information

A Scala Tutorial for Java programmers

A Scala Tutorial for Java programmers A Scala Tutorial for Java programmers Version 1.3 January 16, 2014 Michel Schinz, Philipp Haller PROGRAMMING METHODS LABORATORY EPFL SWITZERLAND 2 1 Introduction This document gives a quick introduction

More information

Exercise 1: Python Language Basics

Exercise 1: Python Language Basics Exercise 1: Python Language Basics In this exercise we will cover the basic principles of the Python language. All languages have a standard set of functionality including the ability to comment code,

More information

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser) High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming

More information

Selection Statements

Selection Statements Chapter 5 Selection Statements 1 Statements So far, we ve used return statements and expression ess statements. e ts. Most of C s remaining statements fall into three categories: Selection statements:

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing.

Computers. An Introduction to Programming with Python. Programming Languages. Programs and Programming. CCHSG Visit June 2014. Dr.-Ing. Computers An Introduction to Programming with Python CCHSG Visit June 2014 Dr.-Ing. Norbert Völker Many computing devices are embedded Can you think of computers/ computing devices you may have in your

More information

Concepts and terminology in the Simula Programming Language

Concepts and terminology in the Simula Programming Language Concepts and terminology in the Simula Programming Language An introduction for new readers of Simula literature Stein Krogdahl Department of Informatics University of Oslo, Norway April 2010 Introduction

More information

Microsoft Access 3: Understanding and Creating Queries

Microsoft Access 3: Understanding and Creating Queries Microsoft Access 3: Understanding and Creating Queries In Access Level 2, we learned how to perform basic data retrievals by using Search & Replace functions and Sort & Filter functions. For more complex

More information

Testing and Tracing Lazy Functional Programs using QuickCheck and Hat

Testing and Tracing Lazy Functional Programs using QuickCheck and Hat Testing and Tracing Lazy Functional Programs using QuickCheck and Hat Koen Claessen 1, Colin Runciman 2, Olaf Chitil 2, John Hughes 1, and Malcolm Wallace 2 1 Chalmers University of Technology, Sweden

More information

Introduction to Python

Introduction to Python Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment

More information

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2). CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical

More information

POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful

POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful RALF HINZE Institute of Information and Computing Sciences Utrecht University Email: ralf@cs.uu.nl Homepage: http://www.cs.uu.nl/~ralf/

More information

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers 0.. +127. char variables mostly used to store characters

More information

3.GETTING STARTED WITH ORACLE8i

3.GETTING STARTED WITH ORACLE8i Oracle For Beginners Page : 1 3.GETTING STARTED WITH ORACLE8i Creating a table Datatypes Displaying table definition using DESCRIBE Inserting rows into a table Selecting rows from a table Editing SQL buffer

More information

A Case Study in DSL Development

A Case Study in DSL Development A Case Study in DSL Development An Experiment with Python and Scala Klaus Havelund Michel Ingham David Wagner Jet Propulsion Laboratory, California Institute of Technology klaus.havelund, michel.d.ingham,

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

CS 2112 Spring 2014. 0 Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

CS 2112 Spring 2014. 0 Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions CS 2112 Spring 2014 Assignment 3 Data Structures and Web Filtering Due: March 4, 2014 11:59 PM Implementing spam blacklists and web filters requires matching candidate domain names and URLs very rapidly

More information

Part 1 Foundations of object orientation

Part 1 Foundations of object orientation OFWJ_C01.QXD 2/3/06 2:14 pm Page 1 Part 1 Foundations of object orientation OFWJ_C01.QXD 2/3/06 2:14 pm Page 2 1 OFWJ_C01.QXD 2/3/06 2:14 pm Page 3 CHAPTER 1 Objects and classes Main concepts discussed

More information

Programming Languages in Artificial Intelligence

Programming Languages in Artificial Intelligence Programming Languages in Artificial Intelligence Günter Neumann, German Research Center for Artificial Intelligence (LT Lab, DFKI) I. AI programming languages II. Functional programming III. Functional

More information

Computational Mathematics with Python

Computational Mathematics with Python Boolean Arrays Classes Computational Mathematics with Python Basics Olivier Verdier and Claus Führer 2009-03-24 Olivier Verdier and Claus Führer Computational Mathematics with Python 2009-03-24 1 / 40

More information

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

More information

CHAPTER 2. Logic. 1. Logic Definitions. Notation: Variables are used to represent propositions. The most common variables used are p, q, and r.

CHAPTER 2. Logic. 1. Logic Definitions. Notation: Variables are used to represent propositions. The most common variables used are p, q, and r. CHAPTER 2 Logic 1. Logic Definitions 1.1. Propositions. Definition 1.1.1. A proposition is a declarative sentence that is either true (denoted either T or 1) or false (denoted either F or 0). Notation:

More information

Introduction to Python

Introduction to Python WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.

More information

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,

More information

Special Directions for this Test

Special Directions for this Test 1 Spring, 2013 Name: (Please do not write your id number!) COP 4020 Programming Languages I Test on Haskell and Functional Programming Special Directions for this Test This test has 7 questions and pages

More information

C H A P T E R Regular Expressions regular expression

C H A P T E R Regular Expressions regular expression 7 CHAPTER Regular Expressions Most programmers and other power-users of computer systems have used tools that match text patterns. You may have used a Web search engine with a pattern like travel cancun

More information

Outline Basic concepts of Python language

Outline Basic concepts of Python language Data structures: lists, tuples, sets, dictionaries Basic data types Examples: int: 12, 0, -2 float: 1.02, -2.4e2, 1.5e-3 complex: 3+4j bool: True, False string: "Test string" Conversion between types int(-2.8)

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

Eventia Log Parsing Editor 1.0 Administration Guide

Eventia Log Parsing Editor 1.0 Administration Guide Eventia Log Parsing Editor 1.0 Administration Guide Revised: November 28, 2007 In This Document Overview page 2 Installation and Supported Platforms page 4 Menus and Main Window page 5 Creating Parsing

More information

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Functional Programming. Functional Programming Languages. Chapter 14. Introduction Functional Programming Languages Chapter 14 Introduction Functional programming paradigm History Features and concepts Examples: Lisp ML 1 2 Functional Programming Functional Programming Languages The

More information

Computational Mathematics with Python

Computational Mathematics with Python Computational Mathematics with Python Basics Claus Führer, Jan Erik Solem, Olivier Verdier Spring 2010 Claus Führer, Jan Erik Solem, Olivier Verdier Computational Mathematics with Python Spring 2010 1

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

Visual Basic Programming. An Introduction

Visual Basic Programming. An Introduction Visual Basic Programming An Introduction Why Visual Basic? Programming for the Windows User Interface is extremely complicated. Other Graphical User Interfaces (GUI) are no better. Visual Basic provides

More information

2. Basic Relational Data Model

2. Basic Relational Data Model 2. Basic Relational Data Model 2.1 Introduction Basic concepts of information models, their realisation in databases comprising data objects and object relationships, and their management by DBMS s that

More information

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer Lecture 10: Static Semantics Overview 1 Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces trees Detects & eliminates ill-formed parse trees Static semantic analysis

More information

Appendix... B. The Object Constraint

Appendix... B. The Object Constraint UML 2.0 in a Nutshell Appendix B. The Object Constraint Pub Date: June 2005 Language The Object Constraint Language 2.0 (OCL) is an addition to the UML 2.0 specification that provides you with a way to

More information

Analyse et Conception Formelle. Lesson 5. Crash Course on Scala

Analyse et Conception Formelle. Lesson 5. Crash Course on Scala Analyse et Conception Formelle Lesson 5 Crash Course on Scala T. Genet (ISTIC/IRISA) ACF-5 1 / 36 Bibliography Simply Scala. Online tutorial: http://www.simply.com/fr http://www.simply.com/ Programming

More information

arrays C Programming Language - Arrays

arrays C Programming Language - Arrays arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)

More information

Lecture 1. Basic Concepts of Set Theory, Functions and Relations

Lecture 1. Basic Concepts of Set Theory, Functions and Relations September 7, 2005 p. 1 Lecture 1. Basic Concepts of Set Theory, Functions and Relations 0. Preliminaries...1 1. Basic Concepts of Set Theory...1 1.1. Sets and elements...1 1.2. Specification of sets...2

More information

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code 1 Introduction The purpose of this assignment is to write an interpreter for a small subset of the Lisp programming language. The interpreter should be able to perform simple arithmetic and comparisons

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named

More information

Variables, Constants, and Data Types

Variables, Constants, and Data Types Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight

More information

6.1. Example: A Tip Calculator 6-1

6.1. Example: A Tip Calculator 6-1 Chapter 6. Transition to Java Not all programming languages are created equal. Each is designed by its creator to achieve a particular purpose, which can range from highly focused languages designed for

More information

Adding GADTs to OCaml the direct approach

Adding GADTs to OCaml the direct approach Adding GADTs to OCaml the direct approach Jacques Garrigue & Jacques Le Normand Nagoya University / LexiFi (Paris) https://sites.google.com/site/ocamlgadt/ Garrigue & Le Normand Adding GADTs to OCaml 1

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

More information

Java Crash Course Part I

Java Crash Course Part I Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe skolbe@wiwi.hu-berlin.de Overview (Short) introduction to the environment Linux

More information

Monads for functional programming

Monads for functional programming Monads for functional programming Philip Wadler, University of Glasgow Department of Computing Science, University of Glasgow, G12 8QQ, Scotland (wadler@dcs.glasgow.ac.uk) Abstract. The use of monads to

More information

Passing 1D arrays to functions.

Passing 1D arrays to functions. Passing 1D arrays to functions. In C++ arrays can only be reference parameters. It is not possible to pass an array by value. Therefore, the ampersand (&) is omitted. What is actually passed to the function,

More information

13 Classes & Objects with Constructors/Destructors

13 Classes & Objects with Constructors/Destructors 13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.

More information

Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance

Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance Introduction to C++ January 19, 2011 Massachusetts Institute of Technology 6.096 Lecture 7 Notes: Object-Oriented Programming (OOP) and Inheritance We ve already seen how to define composite datatypes

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

More information

How To Understand The Theory Of Computer Science

How To Understand The Theory Of Computer Science Theory of Computation Lecture Notes Abhijat Vichare August 2005 Contents 1 Introduction 2 What is Computation? 3 The λ Calculus 3.1 Conversions: 3.2 The calculus in use 3.3 Few Important Theorems 3.4 Worked

More information

Infinite Pretty-printing in exene

Infinite Pretty-printing in exene Infinite Pretty-printing in exene Allen Stoughton Kansas State University Manhattan, KS 66506, USA allen@cis.ksu.edu http://www.cis.ksu.edu/~allen/home.html Abstract. We describe the design and implementation

More information

1.6 The Order of Operations

1.6 The Order of Operations 1.6 The Order of Operations Contents: Operations Grouping Symbols The Order of Operations Exponents and Negative Numbers Negative Square Roots Square Root of a Negative Number Order of Operations and Negative

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved. 1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

COMP 110 Prasun Dewan 1

COMP 110 Prasun Dewan 1 COMP 110 Prasun Dewan 1 12. Conditionals Real-life algorithms seldom do the same thing each time they are executed. For instance, our plan for studying this chapter may be to read it in the park, if it

More information

Using SQL Queries in Crystal Reports

Using SQL Queries in Crystal Reports PPENDIX Using SQL Queries in Crystal Reports In this appendix Review of SQL Commands PDF 924 n Introduction to SQL PDF 924 PDF 924 ppendix Using SQL Queries in Crystal Reports The SQL Commands feature

More information

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

SOLUTION Trial Test Grammar & Parsing Deficiency Course for the Master in Software Technology Programme Utrecht University

SOLUTION Trial Test Grammar & Parsing Deficiency Course for the Master in Software Technology Programme Utrecht University SOLUTION Trial Test Grammar & Parsing Deficiency Course for the Master in Software Technology Programme Utrecht University Year 2004/2005 1. (a) LM is a language that consists of sentences of L continued

More information

Statements and Control Flow

Statements and Control Flow Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to

More information

Python Loops and String Manipulation

Python Loops and String Manipulation WEEK TWO Python Loops and String Manipulation Last week, we showed you some basic Python programming and gave you some intriguing problems to solve. But it is hard to do anything really exciting until

More information

Lecture 5: Java Fundamentals III

Lecture 5: Java Fundamentals III Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd

More information

Scala Programming Language

Scala Programming Language Scala Programming Language Tomáš Bureš DISTRIBUTED SYSTEMS RESEARCH GROUP http://nenya.ms.mff.cuni.cz CHARLES UNIVERSITY PRAGUE Faculty of Mathematics and Physics What is Scala Programming language class-based

More information

OpenInsight 9.3 Quick Start Guide

OpenInsight 9.3 Quick Start Guide OpenInsight 9.3 Quick Start Guide Page 2 of 68 STARTING OPENINSIGHT... 4 I. Starting OpenInsight... 4 II. Opening an Existing Application... 6 III. Creating a New Application... 9 WORKING WITH LINEAR HASH

More information

Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn 2009. Claus Führer Simulation Tools Automn 2009 1 / 65

Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn 2009. Claus Führer Simulation Tools Automn 2009 1 / 65 Simulation Tools Python for MATLAB Users I Claus Führer Automn 2009 Claus Führer Simulation Tools Automn 2009 1 / 65 1 Preface 2 Python vs Other Languages 3 Examples and Demo 4 Python Basics Basic Operations

More information

15-150 Lecture 11: Tail Recursion; Continuations

15-150 Lecture 11: Tail Recursion; Continuations 15-150 Lecture 11: Tail Recursion; Continuations Lecture by Dan Licata February 21, 2011 In this lecture we will discuss space usage: analyzing the memory it takes your program to run tail calls and tail

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

More information

6.170 Tutorial 3 - Ruby Basics

6.170 Tutorial 3 - Ruby Basics 6.170 Tutorial 3 - Ruby Basics Prerequisites 1. Have Ruby installed on your computer a. If you use Mac/Linux, Ruby should already be preinstalled on your machine. b. If you have a Windows Machine, you

More information

Likewise, we have contradictions: formulas that can only be false, e.g. (p p).

Likewise, we have contradictions: formulas that can only be false, e.g. (p p). CHAPTER 4. STATEMENT LOGIC 59 The rightmost column of this truth table contains instances of T and instances of F. Notice that there are no degrees of contingency. If both values are possible, the formula

More information

UML for C# Modeling Basics

UML for C# Modeling Basics UML for C# C# is a modern object-oriented language for application development. In addition to object-oriented constructs, C# supports component-oriented programming with properties, methods and events.

More information

Compiler Construction

Compiler Construction Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from

More information

The countdown problem

The countdown problem JFP 12 (6): 609 616, November 2002. c 2002 Cambridge University Press DOI: 10.1017/S0956796801004300 Printed in the United Kingdom 609 F U N C T I O N A L P E A R L The countdown problem GRAHAM HUTTON

More information