Haskell Cheat Sheet

ADVERTISEMENT

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

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education