**Held**: Wednesday, April 8, 1998

- Any question on assignment five?
- Reminder: there's a cool talk during the math journal club tomorrow.
- Today we'll be moving from Scheme to Haskell so as to explore other issues in functional programming.
- I'll admit that I do most of my Haskell programming on the Mac, so I may rely on the exotic programming languages folks for help running Haskell on our HPs.
- We had a short assignment for today: what is the value of the
following Scheme expression and why?
(let ((a 2)) (+ a (let ((a 4)) a) a))

- Similarly, what's the value of the second of these two expressions
and why?
> (define eh (let ((a 5)) (lambda () a))) > (let ((a 2)) (eh))

- Haskell is a functional language that provides a somewhat different
perspective on functional programming than Scheme.
- Haskell is typed (with an automatic type inference system).
- Haskell is lazy rather than eager (it delays evaluation of expressions "as long as possible"). We'll return to this concept soon.
- Haskell is
*pure*: functions don't have side effects. We also say that Haskell functions are*referentially transparent*: the value they return depends only on the arguments they are sent. - All functions in Haskell are curried.
- Haskell has a different syntax (whoopdedoo)

- The core Haskell web page is at
`http://haskell.org/`

. The*Gentle Introduction to Haskell*at`http://haskell.org/tutorial/index.html`

is a good place to start learning the stuff that I don't teach you.

- Like many functional languages, Haskell has a relatively simple
syntax.
- Function application is notated by the function, a space, and
its argument. For example,
`f a`

represents "apply f to a". - No parentheses are necessary (except for clarity or to circumvent precedence rules).
- Since Haskell is Curried, the apply operation (a space) is
left-associative. For example,
`f a b`

is "apply f to a; apply the resulting function to b". - To get the alternate interpretation (apply a to b, then apply
f to the result), one would write
`f (a b)`

. - Mathematical operations can be written in infix notation, as
in
`a + b`

.

- Function application is notated by the function, a space, and
its argument. For example,
- Haskell uses capitalization to indicate the roles of various
program components. In Haskell, these capitalization standards
are requirements rather than recommendations.
- Functions, variables, and type variables begin with a lowercase letter.
- Types and type constructor begin with an uppercase letter.

- Data types are described with the
`data`

keyword, using the formdata Typename = Definition

- Functions are described by giving the function name, any arguments,
an equals sign, and the body. For example,
fact n = if (n == 0) then 1 else n * (fact (n - 1)

- You can also describe the types of things (e.g., functions), two
colons, and a type expression. For example,
fact :: Int -> Int

- List are written with square brackets and commas between the elements.
All the elements must be the same type. For example,
[4, 2, 4, 1]

- Vectors (also records and products) are written with parentheses and commas between the elemnts.

On to More Haskell Concepts

Back to Scheme, Concluded

Outlines: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

Current position in syllabus

Back to Scheme, Concluded

Outlines: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

Current position in syllabus

**Disclaimer** Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

Source text last modified Thu May 7 20:29:42 1998.

This page generated on Thu May 7 20:34:45 1998 by SiteWeaver.

Contact our webmaster at rebelsky@math.grin.edu