There was no lecture or tutorial this week.
This week we will begin our study of the Haskell language. In our first weeks of learning Haskell we will follow the textbook Learn You a Haskell For Great Good! by Miran Lipovača, which is freely available online.
In this class we will use GHC (the Glasgow Haskell Compiler). You will want to download and install it now.
Haskell is a popular purely functional language with lazy evaluation and a static polymorphic type system using type inference. If you don't know what those terms mean, the section So what's Haskell? in the Lipovača text will give you a brief overview, and your understanding will become clearer as we use Haskell in the weeks to come.
Because Haskell is a purely functional language, the core language
has no mutable variables or data structures. For example, if
you set a variable x to have the value 7, it can never change after
that. Furthermore, the core language has no concept of sequential
execution, i.e. performing one task followed by another. So there are
no while
or for
loops, which are inherently
sequential. If you want to visit all elements of a list or other data
structure, you must use recursion (or a higher-order function which
is itself implemented using recursion). In these respects Haskell is
quite different from traditional languages such as C or Java. On the
other hand, the core of Prolog also has no mutable data, so you
already have experience programming in a language that is somewhat
similar in this respect.
Our goal this week is to learn enough of the Haskell language that we can start writing simple recursive functions using lists and tuples. Specifically, we want to learn about these topics:
integers, including operators +
, -
,
*
, div
, mod
booleans, including operators &&
, ||
,
not
comparison operators ==
, /=
, <
,
<=
, >
, >=
lists, including the list constructor :
and the
concatenation operator ++
basic built-in list functions: head
, tail
,
length
, take
, drop
tuples
if
/ then
/ else
expressions
let
expressions
function definitions
type declarations
type variables
type classes
pattern matching in function definitions
To learn these features, please read the following sections of Learn You a Haskell:
Introduction (all sections)
Starting Out: Ready, set, go!, Baby's first functions, An intro to lists, Tuples
Types and Typeclasses: (all sections)
Syntax in Functions: Pattern matching, Let it be
You do not yet need to
read about ranges, list comprehensions, guards, or where
;
we will visit those topics in the weeks to come.