HASKELL Presentation Programming Segment

Slides:



Advertisements
Similar presentations
User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
Advertisements

Higher-Order Functions and Loops c. Kathi Fisler,
Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
Chapter 7 Sorting Part II. 7.3 QUICK SORT Example left right pivot i j 5 > pivot and should go to the other side. 2 < pivot and should go to.
BBS514 Structured Programming (Yapısal Programlama)1 Functions and Structured Programming.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
Metacircular Evaluation SICP Chapter 4 Mark Boady.
1 CS 161 Introduction to Programming and Problem Solving Chapter 9 C++ Program Components Herbert G. Mayer, PSU Status 10/20/2014.
CSC2100B Quick Sort and Merge Sort Xin 1. Quick Sort Efficient sorting algorithm Example of Divide and Conquer algorithm Two phases ◦ Partition phase.
© 2004 Goodrich, Tamassia QuickSort1 Quick-Sort     29  9.
Creating Functional Programs Brad Vander Zanden. Basic Techniques Tail Recursion – Use continuation arguments if necessary – Akin to pre-processing a.
CS 280 Data Structures Professor John Peterson. Project Questions? /CIS280/f07/project5http://wiki.western.edu/mcis/index.php.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
S: Application of quicksort on an array of ints: partitioning.
1 7.5 Heapsort Average number of comparison used to heapsort a random permutation of N items is 2N logN - O (N log log N).
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
ITEC 380 Organization of programming languages Dr. Andrew Ray.
Functional Programming in Haskell Motivation through Concrete Examples Adapted from Lectures by Simon Thompson.
ISBN Chapter 15 Functional Programming Languages.
Principles of Programming Languages Asst. Prof. Dr. Ahmet Sayar Spring-2012 Kocaeli University Computer Engineering Department Introduction.
Functional programming Functional style makes heavy use of functions as values Hence, functional languages provide powerful constructs for manipulating.
Recitation 11 Analysis of Algorithms and inductive proofs 1.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 7.
HASKELL!. I NTRODUCTION W HAT IS H ASKELL ? Haskell is a computer programming language. In particular, it is a polymorphically statically typed, lazy,
Chapter Fifteen: Functional Programming Languages Lesson 12.
Compiling Functional Programs Mooly Sagiv Chapter 7
EFFICIENCY & SORTING II CITS Scope of this lecture Quicksort and mergesort Performance comparison.
Comparative Programming Languages Language Comparison: Scheme, Smalltalk, Python, Ruby, Perl, Prolog, ML, C++/STL, Java, Haskell.
COMP313A Functional Programming (1)
0 Odds and Ends in Haskell: Folding, I/O, and Functors Adapted from material by Miran Lipovaca.
H ASKELL. I NTRODUCTION W HAT IS H ASKELL ? Haskell is a computer programming language. In particular, it is a polymorphically statically typed, lazy,
Functions Functions, locals, parameters, and separate compilation.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
A Recipe for Algorithm Design Or, What to do when the data type doesn't match the function…yet.
Haskell Chapter 4. Recursion  Like other languages  Base case  Recursive call  Author programs a number of built-in functions as examples.
Logic Programming (Control and Backtracking). Contents Logic Programming –sans Control –with Backtracking Streams.
Haskell Chapter 5, Part II. Topics  Review/More Higher Order Functions  Lambda functions  Folds.
Program Control: Selection Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
1 Vectors, binary search, and sorting. 2 We know about lists O(n) time to get the n-th item. Consecutive cons cell are not necessarily consecutive in.
Introduction To Software Development Environment.
CS314 – Section 5 Recitation 10
Additional Scheme examples
User-Written Functions
Theory of Computation Lecture 4: Programs and Computable Functions II
Introduction to C Language
Chapter 15 – Functional Programming Languages
Functions CIS 40 – Introduction to Programming in Python
Data Structures and Algorithms
Functions Inputs Output
Functions Declarations CSCI 230
Advanced Sorting Methods: Shellsort
The Metacircular Evaluator
FP Foundations, Scheme In Text: Chapter 14.
Functions, Part 2 of 3 Topics Functions That Return a Value
The Metacircular Evaluator
Topics: Programming Constructs: loops & conditionals Digital Input
CS 36 – Chapter 11 Functional programming Features Practice
The Metacircular Evaluator (Continued)
Streams, Delayed Evaluation and a Normal Order Interpreter
Fundamentals of Functional Programming
6.001 SICP Variations on a Scheme
Lecture 11: Multiple representations of abstract data Message passing Overloading Section 2.4, pages ,2.5.2 pages מבוא.
6.001 SICP Interpretation Parts of an interpreter
topics interpreters meta-linguistic abstraction eval and apply
Rehearsal: Lazy Evaluation Infinite Streams in our lazy evaluator
More Scheme CS 331.
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 3 Topics Functions That Return a Value
Advanced Sorting Methods: Shellsort
Presentation transcript:

HASKELL Presentation Programming Segment Anthony Leach

Calculate roots quadratic eq. Input parameter -- function definition roots :: (Float, Float, Float) -> (Float, Float) -- Funct. concrete statements //code provide by www.haskell.org roots (a, b, c) = if d < 0 then error "undefined" else (x1, x2) where x1 = e + sqrt d / (2 * a) x2 = e - sqrt d / (2 * a) d = b * b - 4 * a * c e = -b / (2 * a) -- passing parameters p1, p2, p3, p4 :: (Float, Float, Float) -- Testing diff. values for a, b, c p1 = (1.0, 5.0, 1.0) p2 = (1.0, 1.0, 1.0) p3 = (-2.0, 4.0, 1.0) p4 = (1.0, 14.0, -2.0) Output parameter Function name

Running quad.hs

Comparison of Haskell and C, C++ C or C++ // header file #include stdio.h //Function definition void roots( float, float, float ); //implement file //concrete statements void roots (float a, float b, float c) { ……………… } //main.c int main() roots(a, b, c); HASKELL -- function definition roots :: (Float, Float, Float) -> (Float, Float) --concrete statements roots (a, b, c) = (x1, x2) where x1 = e + sqrt d / (2 * a) x2 = e - sqrt d / (2 * a) d = b * b - 4 * a * c e = -b / (2 * a) Readable Powerful No or low setup time for programming environment

Comparison of Haskell, C, Scheme Powerful Efficient Quicksort in Haskell code provide by haskell.org qsort [] = [] qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x where elts_lt_x = [y | y <- xs, y < x] elts_greq_x = [y | y <- xs, y >= x] Quicksort in Scheme (define quicksort (lambda (ls) (if (null? ls) '() (let* ((pivot (car ls)) (rest (cdr ls)) (left (partition < pivot rest)) (right (partition >= pivot rest))) (append (quicksort left) (list pivot) (quicksort right)))))) Quicksort in C qsort( a, lo, hi ) int a[], hi, lo; { int h, l, p, t; if (lo < hi) { l = lo; h = hi; p = a[hi]; do { while ((l < h) && (a[l] <= p)) l = l+1; while ((h > l) && (a[h] >= p)) h = h-1; if (l < h) { t = a[l]; a[l] = a[h]; a[h] = t; } …………………………….

Final Notes Haskell is a very high-level language (many details taken care of automatically). Haskell is expressive and concise (can achieve a lot with a little effort). Haskell is good at handling complex data and combining components.