Skip to content

Notes for Week 1 Introduction

mattcallanan edited this page Dec 9, 2011 · 2 revisions

Links:

Chapter Review

The three big topics from Chapter 1: Introduction are: purity, laziness, and static-typing.

Purity

See the "Guerilla Guide" linked above for examples on purity and Referential Transparency.

Laziness

To see Haskell's laziness firsthand, fire up ghci and try the following:

>> let doubleMe xs = map (* 2) xs
>> doubleMe [1..]   -- generates an infinite list of numbers.

This will print 2,4,6 etc endlessly. Press Ctrl-C to cancel. Next try:

>> head(doubleMe [1..])

Notice the result came back very quickly. That's because Haskell doesn't evaluate "doubleMe [1..]" first... "head" is executed first "doubleMe [1..]" is only invoked when "head" asks for it. All "head" needs is the 1 element of the list so that's all that gets evaluated.

Haskell does "call-by-need" compared to Java's "call-by-value".

Call-by-need Notes

Static-typing

Comparing Type Systems

Haskell Paradigms

Clone this wiki locally