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)
“In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.”
—Michel de Montaigne (15331592)
“Histories are more full of examples of the fidelity of dogs than of friends.”
—Alexander Pope (16881744)