Concurrent Clean    up http://www.cs.kun.nl/~clean/
 
  Description: Clean is a pure functional, lazy evaluating programming language (similar to Haskell).

Features:

  • Uniqueness typing: Allows descructive updates on objects with only one reference (prepend a '*')
  • Pure functional, lazy evaluating
  • Strict annotations (prepend a '!')
  • Existential types: Hides the type inside an object (encapsulation, allows OO-like programming)
  • Records, arrays, unboxed arrays
  • Generates highly optimized assembly code
  • Comes with an IDE and a platform-independent GUI (currently only on Windows and Mac)
  • Complete sources of the Clean IDE, compiler etc.. available
  • Free for non-commercial use




 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



  Factorial   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"
Prints "Hello World" onto the screen.


 Hello World   Michael Neumann
module HelloWorld

Start = "Hello World\n"
Prints "Hello World" onto the screen.


 Squares   Michael Neumann
module squares
import StdEnv

Start :: [(Int, String)]
Start = [(a*a," ") \\ a <- [1..10]]
Outputs the squares from 1 to 10.


 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".