Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
YES!
Haskell Logo 1
C++
3 | Jeroen Weijers © 2011 University of Tuebingen
Organisation, Introduction, Defining Functions
LECTURE 1
• Master/Diploma students
- One extra question in weekly exercise
https://cis.informatik.uni-tuebingen.de/afp-ws-1112/
INTRODUCTION
PROGRAMMING IN HASKELL
total = 0;
for (i = 1; i ≤ 10; ++i)
total = total+i;
sum [1..10]
> [1,2,3,4,5] !! 2
3
f(a,b) + c d
f a b + c * d
f a + b
Means (f a) + b,
rather than f (a + b).
Mathematics 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
double x = x + x
% ghci test.hs
> quadruple 10
40
> :r
Ok, modules loaded: Main.
> factorial 10
3628800
xs ns nss
deriving do else if
a = 10 a = 10 a = 10
b = 20 b = 20 b = 20
c = 30 c = 30 c = 30
a = b + c a = b + c
where where
b = 1 means {b = 1;
c = 2 c = 2}
d = a * 2 d = a * 2
Implicit Explicit
grouping grouping
N = a ’div’ length xs
where
a = 10
xs = [1,2,3,4,5]