Haskelldump

Starting a random Haskell dump. Will continue to add to this sporadically.

Factorial

fact 0 = 1
fact n = n*fact(n-1)

HCF and LCM

Note how LCM requires use of a “div” function for integer division

hcf n 0 = n
hcf n m = hcf m (mod n m)
lowcm n m = div (n*m) (hcf n m)

Ackermann Function

ackermann 0 m = m+1
ackermann n 0 = ackermann (n-1) 1
ackermann n m = ackermann (n-1) (ackermann n (m-1))

Tetration

tetration n 0 = 1
tetration n m = n^(tetration n (m-1))

Hyper Operations

Crude, rushed version. Could probably be made better.

hyper 1 n m = n+m
hyper 2 n 0 = 0
hyper h n 0 = 1
hyper h n m = hyper (h-1) n (hyper h n (m-1))

Example of main function

Included because I’m 100% brand new to Haskell and need a reminder.

main :: IO ()
main = print $ hcf 800 1200
Next:
Metastable Linerider
Previous:
Factorial Zeroes
Tags:
Geeking