Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Clean (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples== [[hello world program|Hello world]]: <syntaxhighlight lang="clean"> Start = "Hello, world!" </syntaxhighlight> [[Factorial]]: {| |-valign="bottom" |<syntaxhighlight lang="clean"> fac :: Int -> Int fac 0 = 1 fac n = n * fac (n-1) Start = fac 10 </syntaxhighlight> |<syntaxhighlight lang="clean"> fac :: Int -> Int fac n = prod [1..n] // The product of the numbers 1 to n Start = fac 10 </syntaxhighlight> |} [[Fibonacci sequence]]: {| |-valign="bottom" |<syntaxhighlight lang="clean"> fib :: Int -> Int fib 0 = 1 fib 1 = 1 fib n = fib (n - 2) + fib (n - 1) Start = fib 7 </syntaxhighlight> |<syntaxhighlight lang="clean"> fibs :: Int Int -> [Int] fibs x_2 x_1 = [x_2:fibs x_1 (x_2 + x_1)] fib :: Int -> Int fib n = (fibs 1 1) !! n Start = fib 7 </syntaxhighlight> |} [[Infix notation|Infix]] operator: <syntaxhighlight lang="clean"> (^) infixr 8 :: Int Int -> Int (^) x 0 = 1 (^) x n = x * x ^ (n-1) </syntaxhighlight> The type declaration states that the function is a right associative infix operator with priority 8: this states that <code>x*x^(n-1)</code> is equivalent to <code>x*(x^(n-1))</code> as opposed to <code>(x*x)^(n-1)</code>. This operator is pre-defined in StdEnv, the Clean [[standard library]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)