Gofer    up
  similar languages: ML   Haskell   Hope   Objective Caml   Miranda  
  Description: Gofer is a functional Haskell-like language.


 Ackermann   Michael Neumann
ackermann 0 n = n + 1
ackermann m 0 = ackermann (m-1) 1
ackermann m n = ackermann (m-1) (ackermann m (n-1))



 ADT Stack   Michael Neumann
data Keller a = Create | Push (Keller a) a

pop   :: Keller a -> Keller a
top   :: Keller a -> a
empty :: Keller a -> Bool

empty (Create) = True
empty (Push k x) = False
pop (Push k x) = k
top (Push k x) = x

--------------------------------------------

f1 = top(Push (Create) 3)
f2 = top(Push (Push (Create) 3) 4)
f3 = empty(pop(Push (Push (Create) 3) 4))
f4 = Push (pop(Push (Push (Create) 3) 5)) 2
f5 = pop(Push (pop(Push (Push (Create) 3) 4)) 2)
Implementation of the ADT (abstract datatype) Stack.


  Factorial   Michael Neumann
--
-- Fakultaet in Gofer
--

fac :: Int -> Int
fac 0 = 1
fac n = n * fac(n-1)


-- Im Gofer-Interpreter folgendes eingeben: fac 6
Calculates the factorial. Results 720.


 gcd   Michael Neumann
ggt :: Int -> Int -> Int

ggt p q =  if p `rem` q /= 0 then
             ggt q (p `rem` q)
           else
             q
Greatest common divisor


 Hello World   Michael Neumann
show "Hello World"
Prints "Hello World" onto the screen.


  Length of a list   Michael Neumann
len []    = 0
len (h:t) = len t + 1
Determines the length of a list.


 MergeSort   Michael Neumann
mmerge :: [Int] -> [Int] -> [Int]

mmerge []  []  = []
mmerge a   []  = a
mmerge []  b   = b
mmerge (ha:ta) (hb:tb) = if ha < hb then
                           [ha] ++ mmerge ta (hb:tb)
                         else
                           [hb] ++ mmerge (ha:ta) tb


mergesort :: [Int] -> [Int]

mergesort [] = []
mergesort l  = if length l == 1 then l
               else
                 mmerge (mergesort (drop n l))
                        (mergesort (take n l))
                 where n = length l / 2
MergeSort