Concurrent Clean
![]() |
http://www.cs.kun.nl/~clean/ |
Beschreibung: | Clean is a pure functional, lazy evaluating programming
language (similar to Haskell). Features:
|
Ackermann | Michael Neumann |
// // File: Ackermann // Language: Concurrent Clean 2.0 // Author: Michael Neumann (mneumann@ntecs.de) // Date: 23 March 2002 // module Ackermann import StdEnv import ArgEnv Ack :: !Int !Int -> !Int Ack 0 n = n+1 Ack m 0 = Ack (m-1) 1 Ack m n = Ack (m-1) (Ack m (n-1)) Start :: String Start = "Ack(3," +++ toString n +++ "): " +++ toString (Ack 3 n) +++ "\n" where n = toInt (select getCommandLine 1) |
Calculates the Ackermann
function |
Array Access | Michael Neumann |
// // File: Array Access // Language: Concurrent Clean 2.0 // Author: Michael Neumann (mneumann@ntecs.de) // Date: 24 March 2002 // module ArrayAccess import StdEnv import ArgEnv RUNS :== 1000 doIt x y lix = loop RUNS y where // loop 'i' times loop :: !Int *{#Int} -> *{#Int} loop i y # y` = add lix y | i <= 1 = y` | otherwise = loop (i-1) y` where // adds 'x' to 'y' add :: !Int *{#Int} -> *{#Int} add i y #! e = y.[i] # y` = {y & [i] = e + x.[i]} | i == 0 = y` | otherwise = add (i-1) y` Start :: String Start # a = doIt (make_x n) (make_y n) (n-1) = toString a.[0] +++ " " +++ toString a.[n-1] +++ "\n" where n = toInt (select getCommandLine 1) // creates the 'x' array make_x :: !Int -> *{#Int} make_x n = fill_x (createArray n 0) (n-1) where fill_x :: *{#Int} !Int -> *{#Int} fill_x x i | i == 0 = x` | otherwise = fill_x x` (i-1) where x` = {x & [i] = i+1} // creates the 'y' array make_y :: !Int -> *{#Int} make_y n = createArray n 0 |
Fakultät | Michael Neumann |
module Fac fac :: !Int -> Int fac 0 = 1 fac 1 = fac 0 fac n = n * fac (dec n) // Tail recursive (much faster) fact :: !Int !Int -> Int fact 0 i = i fact n i = fact (n-1) (n*i) |
Fibonacci | Michael Neumann |
// // File: Fibonacci // Language: Concurrent Clean 2.0 // Author: Michael Neumann (mneumann@ntecs.de) // Date: 23 March 2002 // module Fibonacci import StdEnv import ArgEnv Fib :: !Int -> !Int Fib n | n < 2 = 1 | otherwise = Fib (n-2) + Fib (n-1) Start :: String Start = "Fib(" +++ toString n +++ "): " +++ toString (Fib n) +++ "\n" where n = toInt (select getCommandLine 1) |
Hello World | Michael Neumann |
// Hello World module helloworld import StdEnv Start :: String Start = "Hello World" |
Gibt "Hello World" auf dem Bildschirm
aus. |
Hello World | Michael Neumann |
module HelloWorld Start = "Hello World\n" |
Gibt "Hello World" auf dem Bildschirm
aus. |
Squares | Michael Neumann |
module squares import StdEnv Start :: [(Int, String)] Start = [(a*a," ") \\ a <- [1..10]] |
Gibt die Quadrate von 1 bis 10
aus. |
String Concatenation | Michael Neumann |
// // File: String Concatenation // Language: Concurrent Clean 2.0 // Author: Michael Neumann (mneumann@ntecs.de) // Date: 25 March 2002 // module StringConcatenation import StdEnv import ArgEnv loop :: !Int *String -> *String loop 0 s = s loop i s = loop (i-1) (s +++. "hello\n") Start = toString (size s) +++ "\n" where s = loop n "" n = toInt (select getCommandLine 1) |
Appends n-times the string
"hello\n". |