Programming 1 Tim Sheard. Spring Quarter Goals of the class – Learn to write simple programs using the programming language Haskell. – Learn by example.

Slides:



Advertisements
Similar presentations
Grade 6 Hopewell Elementary You will read each slide, then try to think of the answer. When you think you know the answer, click ONCE on the mouse.
Advertisements

ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Using Types Slides thanks to Mark Jones. 2 Expressions Have Types: The type of an expression tells you what kind of value you might expect to see if you.
Getting Started with Haskell Tim Sheard. Learning a new language Goals – Learn how to design and use data structures – Learn to write programs using the.
Learning to program. One learns to program by doing. – Writing your own programs – Reading others programs – Studying good programs written by others.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Fixing Broken Programs. How do you figure out what’s wrong? Look carefully at the error message. Locate the error – Most messages have line numbers –
0 PROGRAMMING IN HASKELL Chapter 3 - Types and Classes.
Cse536 Functional Programming 1 7/14/2015 Lecture #2, Sept 29, 2004 Reading Assignments –Begin Chapter 2 of the Text Home work #1 can be found on the webpage,
Using Types Slides thanks to Mark Jones. 2 Expressions Have Types: The type of an expression tells you what kind of value you might expect to see if you.
Basic Elements of C++ Chapter 2.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Chapter 2: Using Data.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Downloading and Installing Autodesk Revit 2016
Chapter 17 Creating a Database.
Variables and Expressions CMSC 201 Chang (rev )
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
© M. Winter COSC 4P41 – Functional Programming Programming with actions Why is I/O an issue? I/O is a kind of side-effect. Example: Suppose there.
UDL Book Builder for Teachers Image sources: Cast UDL.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
Introduction to Objective Caml. General comments ML is a purely functional language--there are (almost) no side effects There are two basic dialects of.
Introduction to Files in VB Chapter 9.1, 9.3. Overview u Data Files  random access  sequential u Working with sequential files  open, read, write,
Lesson 29: Building a Database. Learning Objectives After studying this lesson, you will be able to:  Identify key database design techniques  Open.
Data in Haskell. What is data? Measurements of some kind stored in a computer. – Examples Simple: numbers, text, truth values … Structured: sequences,
An electronic document that stores various types of data.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Introduction to Programming Python Lab 6: Relational Operators and Boolean Variables 12 February PythonLab6 lecture slides.ppt Ping Brennan
Access Test Questions Test Date: 05/05/16. Chapter 1 (Lynda.com) Question 1 An access database uses five main components (database objects). Which is.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Acess Test Questions. Chapter 1 (Lynda.com) Question 1 An access database uses five main components (database objects). Which is not one of them? Tables.
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)
Introduction to Programming
PROGRAMMING IN HASKELL
Introduction to Eclipse
Introducing Instructions
Theory of Computation Lecture 4: Programs and Computable Functions II
Introduction to Computer Science / Procedural – 67130
Computing Fundamentals
Introduction to the JES environment and basics of Python
Variables, Expressions, and IO
Haskell.
CSE 3302 Programming Languages
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Building Java Programs Chapter 2
Introduction to Python and programming
Introduction to Programming
Relational Operators Operator Meaning < Less than > Greater than
Programming Funamental slides
Fundamentals of Functional Programming
Getting Started with Haskell
Tutorial 7 – Integrating Access With the Web and With Other Programs
PROGRAMMING IN HASKELL
Access Test Questions Test Date: 05/05/16.
Introduction to Programming
PROGRAMMING IN HASKELL
Problem 1 Given n, calculate 2n
Intro to Programming (in JavaScript)
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Programming 1 Tim Sheard

Spring Quarter Goals of the class – Learn to write simple programs using the programming language Haskell. – Learn by example. Watch others, study programs – Demo programs Write your own programs – Worksheets – Crib Sheets – Assignments – Pair programming

Pair programming Work in pairs. Two sets of eyes and brains is better than one. One person “drives” – works the keyboard. One person “navigates” – decides strategy and looks for errors. Switch roles at least every half hour. Think before you type!

The programming resource link

In class programming worksheets We will often use worksheets in class – Go to the programming resource link page – Download the worksheet to your own computer – Work in pairs to complete the worksheet. – When your pair is finished. Get up from your table and find a pair that could use some assistance. Over their shoulder (don’t touch the computer!) help them to finish the worksheet – When everyone is standing we’ll move on to the next unit.

Using resources Study the resources provided. Try and recognize what makes a program good. Learn the “structure” of programs. Many errors are silly misspellings or forgotten punctuation. Always ask for help! Many times another pair of eyes will immediately see what’s wrong.

Goals of the programming unit Create simple programs Use simple programs to answer questions that cannot easily be done by hand Use simple programs to find patterns in real world data Process – Acquire data – Manipulate data – Visualize data

Writing a program Start up an editor Start up winhugs Write a program in the editor, save the file “open” the file in winhugs, under the file tab Type “main” in winhugs

Advice Arrange your screen with side by side windows

Interaction in winhugs Type an expression Winhugs checks that it is well formed – Well-typed Evaluates the expression – Carries out the computation Prints the result And the Type

What is data? Measurements of some kind stored in a computer. – Examples Simple: numbers, text, truth values … Structured: sequences, sets, records … Complex: dictionaries, music, pictures …

Data in Haskell Numbers – Integer and Double – 23 – 67.3 Truth Values – Bool – True False Text – String – “Tim” – “23” Sequences – List – [1,3,4] – [True,False]

What kinds of Data can we use? There are many different kinds of data. Haskell comes with a set of predefined data Later we will learn how to define our own (new) kinds of data To see what’s available, click the “Type constructors” under the browse tab. For now – Integer, Bool, List, String

Operations on data To do anything interesting we need operations that compute new data from old data Examples – Integer: div mod (+) (-) (*) – Bool: (&&) (||) not – List: (++) head tail reverse length Operations come in two forms – Prefix: div 8 2 – Infix : 8 * 2 We write surround infix operators with parentheses (*) when we want to talk about them (but not when we use them)

What operations are there? Two different ways to find operations – “name” in the “Browse” tab – “Hierarchical Libraries” in the “Help” Tab Use the slider to look for an operation Or, type its name into the “search” field

Hierarchical Libraries Click “Hierarchical Libraries” in the “help” tab. An internet browser is launched. Slide down to the “Prelude” library

Explore the Prelude Once the prelude window is found - Click the links and explore all the predefined operations in Haskell

Naming Values X = Name equality expression Many program are just a series of named values.

Using implicit types Every legal expression has a type. Examples – Integer – String – Char – Double – [Integer] – Bool

Overloading Some expressions have more than one type. The numeric constants are especially bothersome These will cause you many headaches until you get used to the error messages. Example – 5:: Integer – 5:: Double – 5:: Int – 5:: Num t => t

Commands Commands cause an action on the world. Most commonly used commands perform Input and Output. – Read from the key board getLine, getContents – Print to the console putStrLn, print – Read from files readFile, writeFile

Writing functions

Making lists

Example functions Factorial 99 beer song Rolling two die 12 days of christmas Digitval and string to value Sort maximum, elemIndices, take, dropelemIndices – Maximum, filter, (++)