Clean (programming Language) - Examples

Examples

Hello world:

module hello
Start :: {#Char}
Start = "Hello, world!"

Factorial:

module factorial
fac 0 = 1 fac n = n * fac (n-1) // find the factorial of 10 Start = fac 10

Factorial:

module factorial2
import 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 fibonacci
fib 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:

    Histories are more full of examples of the fidelity of dogs than of friends.
    Alexander Pope (1688–1744)

    It is hardly to be believed how spiritual reflections when mixed with a little physics can hold people’s attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.
    —G.C. (Georg Christoph)

    No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.
    André Breton (1896–1966)