Topic 1: Introduction

Similar documents
CSc 372. Comparative Programming Languages. 4 : Haskell Basics. Department of Computer Science University of Arizona

Topic 9: Type Checking

Topic 9: Type Checking

CSc 372 Comparative Programming Languages. 4 : Haskell Basics

G Programming Languages - Fall 2012

Programming Paradigms

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

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

Visual Basic for Applications

Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions

Lecture 2 Tao Wang 1

CSc 520. Principles of Programming Languages 11: Haskell Basics

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

Functional Programming Languages (FPL)

Full file at

COMP Primitive and Class Types. Yi Hong May 14, 2015

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Special Section: Building Your Own Compiler

Haskell Programs. Haskell Fundamentals. What are Types? Some Very Basic Types. Types are very important in Haskell:

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Program Fundamentals

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Ex: If you use a program to record sales, you will want to remember data:

Datatypes, Variables, and Operations

Introduction to programming with Python

Intro to Haskell Notes: Part 5

printf( Please enter another number: ); scanf( %d, &num2);

REVIEW. The C++ Programming Language. CS 151 Review #2

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Fundamentals: Expressions and Assignment

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

1 Lexical Considerations

Language Reference Manual simplicity

An introduction introduction to functional functional programming programming using usin Haskell

Lexical Considerations

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

CS112 Lecture: Primitive Types, Operators, Strings

7. Introduction to Denotational Semantics. Oscar Nierstrasz

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

Solution sheet 1. Introduction. Exercise 1 - Types of values. Exercise 2 - Constructors

Programming Paradigms

Logical Methods in... using Haskell Getting Started

Computer Components. Software{ User Programs. Operating System. Hardware

Variables, expressions and statements

CS313D: ADVANCED PROGRAMMING LANGUAGE

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

Computational Expression

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

Sprite an animation manipulation language Language Reference Manual

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

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

CIS133J. Working with Numbers in Java

Python for Astronomers. Week 1- Basic Python

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

In this chapter you ll learn:

Topic 6: Partial Application, Function Composition and Type Classes

Topic 6: Partial Application, Function Composition and Type Classes

AP Computer Science A

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

Chapter 17. Fundamental Concepts Expressed in JavaScript

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

On Academic Dishonesty. Declarative Computation Model. Single assignment store. Single assignment store (2) Single assignment store (3)

This example highlights the difference between imperative and functional programming. The imperative programming solution is based on an accumulator

Data types Expressions Variables Assignment. COMP1400 Week 2

Operators. Java Primer Operators-1 Scott MacKenzie = 2. (b) (a)

Computer Programming : C++

6.096 Introduction to C++ January (IAP) 2009

F28PL1 Programming Languages. Lecture 11: Standard ML 1

Differentiate Between Keywords and Identifiers

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

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Functional Programming. Big Picture. Design of Programming Languages

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

Variable A variable is a value that can change during the execution of a program.

CSc Introduction to Computing

Inf1-OOP. Textbooks. Who and What. Organizational Issues. Why Java? Course Overview. Hello, World! in Java. Ewan Klein, Perdita Stevens

Lecture Set 2: Starting Java

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

DaMPL. Language Reference Manual. Henrique Grando

Chapter 2: Programming Concepts

On a 64-bit CPU. Size/Range vary by CPU model and Word size.

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

Basic types and definitions. Chapter 3 of Thompson

Inf1-OOP. Textbooks. Who and What. Organisational issues. Why Java? Course Overview. Hello, World! in Java

Lecture Set 2: Starting Java

Values and Variables 1 / 30

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

ENGR 101 Engineering Design Workshop

Lexical Considerations

MODULE 02: BASIC COMPUTATION IN JAVA

Basics of Java Programming

Transcription:

Recommended Exercises and Readings Topic 1: Introduction From Haskell: The craft of functional programming (3 rd Ed.) Readings: Chapter 1 Chapter 2 1 2 What is a Programming Paradigm? Programming Paradigm: A style or way of programming Influences how you solve problems and implement solutions Languages include features from one or more paradigms Imperative Programming A program consists of a sequence of commands Commands describe how the computation takes place Step by step Modify state Most modern imperative languages are structured Conditionals, loops and subroutines (functions) instead of gotos Variables are generally local to a block or subroutine 3 4

Object Oriented Programming Program describes objects and the ways they interact Emphasizes objects instead of actions and data rather than logic Principal concern is sending messages to objects Objects respond to messages by performing operations Messages can have arguments Look like calling a subroutine Similar objects are abstracted into a class Similar classes grouped together into inheritance hierarchies Often include mechanisms for encapsulation and information hiding Functional Programming Focus is on functions and the application of functions to values Evaluation of expressions rather than running commands Functions can be Constructed as a program runs Passed as parameters to other functions Returned as results from functions Pure functional languages Do not include loops Functions are side effect free No (modifiable) global state 5 6 Logic Programming Program is a collection of facts and inference rules Identify goal Unification and backtracking find a value that satisfies the goal Occurs automatically programmer doesn t specify how to find the solution Human Language In written form Letters are used to form words Words are used to form phrases Phrases are used to form sentences Sentences are used to form paragraphs Paragraphs are used to form sections Sections are used to form chapters Chapters are used to form books 7 8

Human Language But Not every sequence of letters is an allowed word Not every combination of words is an allowed phrase Not every combination of phrases is an allowed sentence Syntax defines the structure of what is allowed Grammar describes syntax Humans attach meaning to words Semantics: The branch of linguistics and logic concerning meaning Ambiguities in Language Look at the bow! 9 10 Programming Languages Syntax: Rules that describe valid combinations of symbols and the structure of a program Semantics: Rules that describe the meaning of the statements Programming languages Communicate instructions to the machine Can be written by a person Minimize ambiguity May be defined by Specification Implementation So Many Programming Languages! 18 19

So Many Programming Languages! Almost all programming languages are Turing complete With enough time and memory, they can compute anything that is computable Why are there so many programming languages? Programming languages evolve Learn from predecessors New problems may be easier to solve with new languages Different tools for different jobs Trade offs between safety, speed and convenience Different people have different tastes and abilities Variety is beneficial! 20 Haskell A functional programming language Originally developed in the 1990s Successor to Miranda General purpose Pure Offers several interesting features Strong type system with type inference and type classes Lazy evaluation Pattern matching List comprehensions Can be interpreted or compiled Popular in academia, and has seen some industrial use 21 Getting Haskell Download it for free https://www.haskell.org/downloads I used the Haskell Platform installer Available for Windows, Linux and MacOS Probably more than what you really need You ll also need your favourite editor Writing our First Function To define a function in Haskell we need It s name It s type Types of parameters passed to the function Type of the value returned by the function Syntactic requirements: Function names must start with a lowercase letter Types start with uppercase letters Function name is separated from its type by :: 22 23

Functions: Definitions in Different Languages Define a function named alwaysfive which always returns the Int 5 Haskell Types Int Fixed Range 2 64 to 2 64 1 on my system Integer Arbitrarily large integers Convert to/from other numeric types with tointeger and frominteger Float Operation Addition Subtraction Multiplication Division (Truncated integer result) Remainder Round to closest integer Absolute value + * quot rem abs Number with both an integer and fractional part Convert to/from other numeric types with tointegral/fromintegral Operator / Function round 24 25 Haskell Types Functions: Adding Parameters Boolean True or False Operators: &&, and not Char Literals enclosed in single quotes String Literals enclosed in double quotes Equivalent to [Char] Char: 'a', String ['a'] or "a" Concatenate strings with ++ 26 Define a function that returns twice it s Int parameter 27

Functions: Additional Parameters Define a fused multiply add function which computes a * b + c, where a, b and c are all of type Float Calling Functions Brackets aren t needed for many function calls in Haskell Places where brackets are needed Negative numbers Grouping to avoid passing a function as one of the parameters 28 29 Summary Programming languages Four broad paradigms Some languages have features from multiple paradigms Provide a mechanism to communicate with the computer Haskell A functional programming language Function type declaration: name :: Type Function implementation: name args = body 30