Examples
Hello world:
module helloStart :: {#Char}
Start = "Hello, world!"
Factorial:
module factorialfac 0 = 1 fac n = n * fac (n-1) // find the factorial of 10 Start = fac 10
Factorial:
module factorial2import StdEnv fac 0 = 1 fac n = prod //Generate a list that goes from 1 to n and returns the product of the elements // find the factorial of 6 Start = fac 6
Fibonacci sequence:
module fibonaccifib 0 = 0 fib 1 = 1 fib n = fib (n - 2) + fib (n - 1)
Start = fib 7
Infix operator:
(^) infixr 8 :: Int Int -> Int (^) x 0 = 1 (^) x n = x * x ^ (n-1)The type declaration states that the function is a right associative infix operator with priority 8: this states that x*x^(n-1)
is equivalent to x*(x^(n-1))
as opposed to (x*x)^(n-1)
; this operator is pre-defined in the Clean standard environment.
Read more about this topic: Clean (programming Language)
Famous quotes containing the word examples:
“No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.”
—André Breton (18961966)
“There are many examples of women that have excelled in learning, and even in war, but this is no reason we should bring em all up to Latin and Greek or else military discipline, instead of needle-work and housewifry.”
—Bernard Mandeville (16701733)
“Histories are more full of examples of the fidelity of dogs than of friends.”
—Alexander Pope (16881744)