Installation and exercises

Slides:



Advertisements
Similar presentations
Lecture 07 – Iterating through a list of numbers.
Advertisements

Comp 205: Comparative Programming Languages Functional Programming Languages: More Haskell Nested definitions Lists Lecture notes, exercises, etc., can.
Functions in MatLab Create a new folder on your Z:drive called MatLab_Class24 Start MatLab and change your current directory to MatLab_Class24 Topics:
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
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 2 - First Steps.
Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A.
0 PROGRAMMING IN HASKELL Chapter 3 - Types and Classes.
1 (Functional (Programming (in (Scheme)))) Jianguo Lu.
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.
0 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)
Department of Computer Science Data Structures Using C++ 2E Chapter 6: Recursion Learn about recursive Definitions Algorithms Functions Explore the base.
Definitions. name :: Type answer :: Int name = expression answer = Definitions associate a name with a value of a certain type is of type greater.
0 PROGRAMMING IN HASKELL Chapter 5 – Introduction, The Hugs System, Types and Classes.
0 REVIEW OF HASKELL A lightening tour in 45 minutes.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 7.
Scheme & Functional Programming. ( ) >> 64 ( ) >> 666 (* ) >> 1200 (+ (* 3 5) (- 10 6)) >> 19.
Haskell Starting Out Piotr Poniatowski Łukasz Reszczyński Maciej Woźniczka.
0 PROGRAMMING IN HASKELL Some first steps Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Chapter 9: Functional Programming in a Typed Language.
Overview of the Haskell 98 Programming Language
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.
Discrete Structure Li Tak Sing( 李德成 ) Lecture 13 1.
Lee CSCE 314 TAMU 1 CSCE 314 Programming Languages Haskell 101 Dr. Hyunyoung Lee.
Operator precedence.  Evaluate a + b * c –multiplication first? a + (b * c) –addition first? ( a + b) * c  Java solves this problem by assigning priorities.
Recursion on Lists Lecture 5, Programmeringsteknik del A.
Data in Haskell. What is data? Measurements of some kind stored in a computer. – Examples Simple: numbers, text, truth values … Structured: sequences,
9.1 Sequences and Series. Definition of Sequence  An ordered list of numbers  An infinite sequence is a function whose domain is the set of positive.
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.
0 PROGRAMMING IN HASKELL Chapter 2 - First Steps.
Functional Programming Lecture 3 - Lists Muffy Calder.
Haskell Chapter 5, Part II. Topics  Review/More Higher Order Functions  Lambda functions  Folds.
Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office Functional Programming.
1 PROGRAMMING IN HASKELL Lecture 2 Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
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.
Lecture 14: Advanced Topic: Functional Programming
Polymorphic Functions
Midterm recap Total was 80 points Distribution range
dr Robert Kowalczyk WMiI UŁ
PROGRAMMING IN HASKELL
Types CSCE 314 Spring 2016.
Learning to Program D is for Digital.
PROGRAMMING IN HASKELL
A lightening tour in 45 minutes
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
CSE 3302 Programming Languages
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
Formatted and Unformatted Input/Output Functions
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
Clojure to Haskell (It’s mostly syntax).
PROGRAMMING IN HASKELL
Haskell Types, Classes, and Functions, Currying, and Polymorphism
PROGRAMMING IN HASKELL
Fundamentals of Functional Programming
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
Functional Programming
CSCE 314: Programming Languages Dr. Dylan Shell
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
 A function is a named sequence of statement(s) that performs a computation. It contains  line of code(s) that are executed sequentially from top.
Presentation transcript:

Installation and exercises HASKELL Installation and exercises

Installation http://www.haskell.org Main Page  Download Haskell Haskell Engine + GHCi In Windows: Also WinGHCi GHCi: Haskell Compiler/Interpreter

GHCi

Interpreter: Try it out! Math Operations and Functions 2 + 2 10^2 log(10) Lists [1, 2, 3] [1..10] [“x”, ”y”, ”z”] [‘x’, ’y’, ’z’] Variable Assignment let x = 5 in x^2 + 2*x + 4

Running Haskell Script Files Create a new file, “HelloWorld.hs” main = do putStrLn "Hello, world!" Change the current directory: :cd <Directory of HS file> Load the file: :load HelloWorld.hs Run the file: main

Running Haskell Files

Basic List Manipulation Get first element: head <list> Get last element: tail <list> Get nth element: <list> !! N Get first n elements: take n <list> Remove first n elements: drop n <list> Length of list: length <list> Sum of numbers: sum <list> Product of numbers: product <list> Append lists: <list1> ++ <list2> Reverse list: reverse <list>

Functions in Haskell Prefix Operations: Operation before operands. In Math: f(x,y) + z In Haskell: f x y + z Function has higher priority In Math: f(x,y+z) In Haskell: f x (y+z) Function of functions In Math: f(x,g(y)) In Haskell: f x (g y) Recursion is highly encouraged

Defining functions Defined in a Haskell script file Example: The “=“ operator Arguments Example: double x = x + x squared x = x * x hypothenuse x y = sqrt(x^2 + y^2)

Implicit Grouping Used when defining functions Same spacing/tabbing to denote groups hypothenuse2 x y = sqrt(z) where z = x2 + y2 x2 = x^2 y2 = y^2

Exercises Fix the syntax error and try the following program: N = a ’div’ length xs where a = 10 xs = [1,2,3,4,5]

Exercises Write two possible definitions of the ‘lastOne’ function that selects the last element of a list. Write two possible definitions of an ‘init’ function that removes the last element of a list. Write a function that receives a list and returns a list of the original values of the list plus two

Exercises Write a function for the factorial operation Write a function that receives a numerical user input and returns the factorial of that number To obtain user input: X <- readLn Write a function that receives a numerical user input ‘x’ and returns a list from 0 to x

Exercises EXTRA: Write a function that calculates the nth number of the Fibonacci sequence Fibonacci numbers: f(n) = f(n-1) + f(n-2) f(0) = 1 f(1) = 1