Use ghci filename.hs
to start with a file loaded.
When in ghci, here are some useful commands:
:load file.hs
:reload
or :r
:set editor <name>
to set editor to name:edit <name>
to edit script name:edit
to edit current script:show modules
:show imports
:type <expr>
to show type of expression expr
:?
for help:quit
s
suffix. E.g. xs
, ns
, nss
.Haskell has library functions. Many functions are useful on lists. Imagine the lists have elements. x
represents a number.
head []
tail []
.[] !! x
take x []
drop x []
length []
sum []
product []
[] ++ []
reverse []
Function application is denoted using space.
Multiplication is denoted using *
.
E.g. call f
with parameters a
and b
: f a b
Function calls have higher priority than any other operator.
f a + b
means (f a) + b
.
A function can be a total function or a Partial function.
Math | Haskell | |
---|---|---|
$f(x)$ | f x | |
$f(x,y)$ | f x y | |
$f(g(x))$ | f (g x ) | |
$f(x,g(y))$ | f x (g y) | |
$f(x)g(y)$ | f x * g y |
In a sequence of definitions, each definition must begin in precisely the same column.
Meaning, it works on indentation. So you don’t need to explicitly define groupings of definitions.
Use ghci filename.hs
to start with a file loaded.
When in ghci, here are some useful commands:
:load file.hs
:reload
or :r
:set editor <name>
to set editor to name:edit <name>
to edit script name:edit
to edit current script:show modules
:show imports
:type <expr>
to show type of expression expr
:?
for help:quit
s
suffix. E.g. xs
, ns
, nss
.Haskell has library functions. Many functions are useful on lists. Imagine the lists have elements. x
represents a number.
head []
tail []
.[] !! x
take x []
drop x []
length []
sum []
product []
[] ++ []
reverse []
Function application is denoted using space.
Multiplication is denoted using *
.
E.g. call f
with parameters a
and b
: f a b
Function calls have higher priority than any other operator.
f a + b
means (f a) + b
.
A function can be a total function or a Partial function.
Math | Haskell | |
---|---|---|
$f(x)$ | f x | |
$f(x,y)$ | f x y | |
$f(g(x))$ | f (g x ) | |
$f(x,g(y))$ | f x (g y) | |
$f(x)g(y)$ | f x * g y |
In a sequence of definitions, each definition must begin in precisely the same column.
Meaning, it works on indentation. So you don’t need to explicitly define groupings of definitions.