Miranda    up
  similar languages: ML   Haskell   Gofer   Hope   Objective Caml  
 


  Factorial (1)   Michael Neumann
fac 0 = 1
fac 1 = 1
fac n = n * fac (n-1) 
Calculates the factorial. Results 720.


  Factorial (2)   Michael Neumann
fac n = n * fac (n-1),  if n >= 2 
      = 1,              if n < 2 
Calculates the factorial. Results 720.


 gcd   Martin Guy
  gcd a b = gcd (a-b) b,  if a>b
          = gcd a (b-a),  if a<b
          = a,            if a=b
Greatest common divisor


 Hello World   Martin Guy
"Hello World!"
Prints "Hello World" onto the screen.


 Quicksort   Martin Guy
qsort []    = []
qsort (a:x) = qsort [ b | b <- x; b<=a ]
              ++ [a] ++
              qsort [ b | b <- x; b>a ]
Quicksort sorting algorithm


 Squares (1)   Martin Guy
map (^2) [1..10]
Outputs the squares from 1 to 10.


 Squares (2)   Martin Guy
[ n*n | n <- [1..10] ]
Outputs the squares from 1 to 10.