Download presentation
Presentation is loading. Please wait.
Published byRoberta Hensley Modified over 9 years ago
1
Haskell Introduction CSCE 314 Spring 2016
2
CSCE 314 – Programming Studio Historical Background 1930s: Alonzo Church develops the lambda calculus, a simple but powerful theory of functions.
3
Spring 2016 CSCE 314 – Programming Studio 1950s: John McCarthy develops Lisp, the first functional language, with some influences from the lambda calculus, but retaining variable assignments
4
Spring 2016 CSCE 314 – Programming Studio 1960s: Peter Landin develops ISWIM, the first pure functional language, based strongly on the lambda calculus, with no assignments
5
Spring 2016 CSCE 314 – Programming Studio 1970s: John Backus develops FP, a functional language that emphasizes higher order functions and reasoning about programs.
6
Spring 2016 CSCE 314 – Programming Studio 1970s: Robin Milner and others develop ML, the first modern functional language, which introduced type inference and polymorphic types.
7
Spring 2016 CSCE 314 – Programming Studio 1970s-1980s: David Turner develops a number of lazy functional languages, culminating in the Miranda system
8
Spring 2016 CSCE 314 – Programming Studio 1987: An international committee of researchers initiates the development of Haskell, a standard lazy pure functional language
9
Spring 2016 CSCE 314 – Programming Studio 2003: The committee publishes the Haskell 98 report, defining a stable version of the language. Since then, Haskell has become highly influential in language research and fairly widely used in open- source/commercial software.
10
Spring 2016 CSCE 314 – Programming Studio Haskell is a Lazy Pure Functional Language
11
Spring 2016 CSCE 314 – Programming Studio “Haskell is a Lazy Pure Functional Language” A Functional language supports the functional programming style where the basic method of computation is application of functions to arguments. For example, in C, int s = 0; for (int i=1; i <= 100; ++i) s = s + i; the computation method is variable assignment. In Haskell, sum [1..100] the computation method is function application.
12
Spring 2016 CSCE 314 – Programming Studio Briefly: Defining functions in Haskell To define a function, you state (in order): the name of the function the arguments it takes an equals sign the result of the function For example: double x = x + x says that double takes a parameter x and returns twice x, so that: double 10 20 We will have much more to say about this in the future…
13
Spring 2016 CSCE 314 – Programming Studio Features of Functional Languages Higher-order functions are functions that take other functions as their arguments. e.g., > map reverse ["abc","def"] ["cba","fed”] Purity – prohibits side effects (Expressions may result in some actions in addition to return values, such as changing state and I/O; these actions are called side effects.) Recursion – the canonical way to iterate in functional languages
14
Spring 2016 CSCE 314 – Programming Studio “Haskell is a Lazy Pure Functional Language” A Lazy programming language only evaluates arguments when strictly necessary, thus, (1)avoiding unnecessary computation and (2)ensuring that programs terminate whenever possible.
15
Spring 2016 CSCE 314 – Programming Studio “Haskell is a Lazy Pure Functional Language” A Lazy programming language only evaluates arguments when strictly necessary, thus, (1)avoiding unnecessary computation and (2)ensuring that programs terminate whenever possible.
16
Spring 2016 CSCE 314 – Programming Studio “Haskell is a Lazy Pure Functional Language” A Lazy programming language only evaluates arguments when strictly necessary. For example, given the definitions omit x = 0 keep_going x = keep_going (x+1) what is the result of the following expression? omit (keep_going 1)
17
Spring 2016 CSCE 314 – Programming Studio “Haskell is a Lazy Pure Functional Language” A Lazy programming language only evaluates arguments when strictly necessary. For example, given the definitions omit x = 0 keep_going x = keep_going (x+1) what is the result of the following expression? omit (keep_going 1) Answer: 0 Since omit is defined to be 0, it doesn‘t matter what is inside.
18
Spring 2016 CSCE 314 – Programming Studio “Haskell is a Lazy Pure Functional Language” A Pure functional language, as with mathematical functions, prohibits side effects (or at least they are confined): Data is immutable: Instead of altering existing values, altered copies are created and the original is preserved. Thus, there’s no destructive assignment: a = 1; a = 2; -- illegal
19
Spring 2016 CSCE 314 – Programming Studio “Haskell is a Lazy Pure Functional Language” A Pure functional language, as with mathematical functions, prohibits side effects (or at least they are confined): Expressions yield the same value each time they are invoked. Referential transparency This helps with reasoning. An expression can be replaced with its value without changing the behavior of a program For example, if we have defined y = f x Then g = h y y and g = h (f x) (f x) are equivalent and will get the same result (value).
20
Spring 2016 CSCE 314 – Programming Studio “Haskell is a Lazy Pure Functional Language” A Pure functional language, as with mathematical functions, prohibits side effects (or at least they are confined): Referential Transparency: For example, if we have defined y = f x Then g = h y y and g = h (f x) (f x) are equivalent and will get the same result (value).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.