What I learned in 30 minutes

4 + 5 + 1

10

That above is an infix function, but you can also define your own function like that:

add a b = a + b

add 2 2

4
99 add 991

1090

Reduce operations (reduce() in python, etc.) are foldl.

This function takes the first function, the starting value, and folds the function by adding it from the left.

foldl add 0 [1..100]

5050

Here, the tutorial shows me how to define the infamous fib function … otherwise is actually just true and hence always the last fallthrough case.

fib x
| x < 2 = 1
| otherwise = fib (x - 1) + fib (x - 2)


5-th fibonacci number is 8 (well, we’re the cool guys, and count from 0)

fib 5

8

Use show to print a string and “.”-combine this via a $-sign (for lowering the precedence) to apply the argument to the fib function. show . fib$ 0
show . fib $1 show . fib$ 2

"1"
"1"
"2"

map applies a function over a list – where the .. create it in a lazy fashion …

map fib [0..20]

[1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946]



## Linear Algebra via hmatrix

import Numeric.LinearAlgebra

a = (2><2)
[ 1, 2
, 3, 4 ] :: Matrix R

b = (2><1)
[ 5
, 6 :: R ]

disp 3 a

2x2 1 2 3 4
disp 3 b

2x1 5 6
let x = linearSolve a b
x

Just (2><1) [ -3.9999999999999987 , 4.499999999999999 ]
let c = (5><3) [1..] :: Matrix R
c

(5><3) [ 1.0, 2.0, 3.0 , 4.0, 5.0, 6.0 , 7.0, 8.0, 9.0 , 10.0, 11.0, 12.0 , 13.0, 14.0, 15.0 ]
let (u,s,v) = svd c

disp 3 u

5x5 -0.101 0.768 0.614 -0.105 0.110 -0.249 0.488 -0.696 0.185 0.426 -0.396 0.208 -0.274 -0.453 -0.721 -0.543 -0.072 0.180 0.770 -0.274 -0.690 -0.352 0.176 -0.397 0.460



## Installed Libraries

import System.Process

callCommand "cabal list --installed"