Data in Haskell. What is data? Measurements of some kind stored in a computer. – Examples Simple: numbers, text, truth values … Structured: sequences,

Slides:



Advertisements
Similar presentations
0 PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions.
Advertisements

Pemrograman VisualMinggu …2… Page 1 MINGGU Ke Dua Pemrograman Visual Pokok Bahasan: Console Application Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Operators, Functions and Modules1 Operators and Functions.
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.
0 PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions.
Chapter 3 Simple Graphics. Side Effects and Haskell  All the programs we have seen so far have no “side-effects.” That is, programs are executed only.
Introduction to Computer Science Exam Information Unit 20.
Programming 1 Tim Sheard. Spring Quarter Goals of the class – Learn to write simple programs using the programming language Haskell. – Learn by example.
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.
Programming is instructing a computer to perform a task for you with the help of a programming language.
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.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
Chapter 2: Using Data.
Variables and Expressions CMSC 201 Chang (rev )
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Building Java Programs Primitive Data and Definite Loops.
1 Building Java Programs Chapter 7: Arrays These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold, or.
Overview of the Haskell 98 Programming Language
© 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.
What is a Type? A type is a name for a collection of related values. For example, in Haskell the basic type Bool contains the two logical values: True.
12/15/2015Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays.
Week 3 - Friday.  What did we talk about last time?  Operations on boolean values  !, &&, ||  Operations on char values  +, -  Operations on String.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
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.
Fundamental Programming Fundamental Programming More Expressions and Data 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.
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 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 15, 2004 Lecture Number: 11.
24-Jun-16 Haskell Dealing with impurity. Purity Haskell is a “pure” functional programming language Functions have no side effects Input/output is a side.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
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)
0 PROGRAMMING IN HASKELL Typeclasses and higher order functions Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and.
6-Jul-16 Haskell II Functions and patterns. Data Types Int + - * / ^ even odd Float + - * / ^ sin cos pi truncate Char ord chr isSpace isUpper … Bool.
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x2 | x  {1...5}} The set {1,4,9,16,25}
dr Robert Kowalczyk WMiI UŁ
PROGRAMMING IN HASKELL
Types CSCE 314 Spring 2016.
Theory of Computation Lecture 4: Programs and Computable Functions II
Introduction to Computer Science / Procedural – 67130
Data Types, Identifiers, and Expressions
Haskell.
CSE 3302 Programming Languages
Installation and exercises
Introduction to Python
Haskell Dealing with impurity 30-Nov-18.
Programming Funamental slides
Introduction to Primitive Data types
Lec 4: while loop and do-while loop
Type & Typeclass Syntax in function
PROGRAMMING IN HASKELL
Haskell Dealing with impurity 8-Apr-19.
Life is Full of Alternatives
Life is Full of Alternatives
PROGRAMMING IN HASKELL
Functions and patterns
PROGRAMMING IN HASKELL
Introduction to data structures
Haskell Dealing with impurity 29-May-19.
Introduction to data structures
Haskell Dealing with impurity 28-Jun-19.
Problem 1 Given n, calculate 2n
Introduction to Primitive Data types
Presentation transcript:

Data in Haskell

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 – Int, Integer, Double etc. – 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 For now – Integer, Bool, List, String Later we will learn how to define our own (new) kinds of data Stack, Queue, Tree, Table, Hash, …

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? Many different ways to find operations – Click on the Libraries link from the users guide – Use one of the crib sheets from the Haskell Resource Links

Hierarchical Libraries Click “Libraries” from the users guide 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, (++)