Haskell

haskell

This is my first functional programming language.

% cat test.hs
main = do
    putStrLn "CQ de JH1OOD"

% ghc -o test test.hs
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ...

% ./test
CQ de JH1OOD

% ghci
GHCi, version 7.10.3
Prelude> let fact :: Int -> Int; fact n = if n == 0 then 1 else n * fact (n-1)
Prelude> fact 10
3628800
Prelude> fact 20
2432902008176640000

% cat fact.hs
fact :: Integer -> Integer 
fact n = if n == 0 then 1 else n * fact (n-1)
main = do
    print $ fact 30

% ghc -o fact fact.hs
[1 of 1] Compiling Main             ( fact.hs, fact.o )
Linking fact ...
% ./fact
265252859812191058636308480000000

% cat fibo.hs
fibo :: Integer -> Integer
fibo 0 = 0
fibo 1 = 1
fibo n = fibo (n-2) + fibo (n-1)
main = do
    print $ fibo 20

% ghc -o fibo fibo.hs && ./fibo
6765

Leave a Reply

Your email address will not be published. Required fields are marked *