Haskell Cheat Sheet

ADVERTISEMENT

Haskell Cheat Sheet
Strings
Enumerations
– List of numbers –
. . .
.
– Unicode string.
This cheat sheet lays out the fundamental elements
– Infinite list of numbers –
– Single character.
of the Haskell language: syntax, keywords and
. . . .
other elements.
It is presented as both an ex-
Multi-line Strings
Normally, it is syntax error if
– Empty list; ranges only go forwards.
ecutable Haskell file and a printable document.
a string has any actual new line characters. That is,
– Negative integers.
Load the source into your favorite interpreter to
this is a syntax error:
– Syntax error; need
play with code samples shown.
for negatives.
– List from 1 to 100 by
2, -1 to 100 by 4.
Syntax
However, backslashes (‘ ’) can be used to “escape”
In fact, any value which is in the
class can be
around the new line:
Below the most basic syntax for Haskell is given.
used. E.g.,:
– List of characters –
. . .
.
.
Comments
– List of
A single line comment starts with ‘ ’ and extends
values (from
).
The area between the backslashes is ignored. An
to the end of the line. Multi-line comments start
important note is that new lines in the string must
with ’ ’ and extend to ’ ’. Comments can be
still be represented explicitly:
Lists & Tuples
nested.
– Empty list.
Comments above function definitions should
– List of three numbers.
start with ‘
’ and those next to parameter types
– Alternate way to write lists us-
with ‘
’ for compatibility with Haddock, a sys-
That is,
evaluates to:
ing “cons” ( ) and “nil” ( ).
tem for documenting Haskell code.
– List of three characters (strings are lists).
– List of characters (same
Reserved Words
as
).
While
evaluates to:
– 2-element tuple of a number and a string.
The following lists the reserved words defined by
– 4-element tuple of two
Haskell. It is a syntax error to give a variable or
functions, a number and a character.
function one of these names.
“Layout” rule, braces and semi-colons.
Numbers
Haskell can be written using braces and semi-
- Integer
colons, just like C. However, no one does. Instead,
- Floating point
the “layout” rule is used, where spaces represent
c 2008 Justin Bailey.
1

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education