Standard examples (examples/standard/): - hello_world: Basic effect usage - fizzbuzz: Classic programming exercise - factorial: Recursive and tail-recursive versions - primes: Prime number generation - guessing_game: Interactive Random + Console effects - stdlib_demo: Demonstrates List, String, Option, Math modules Showcase examples (examples/showcase/): - ask_pattern: Resumable effects for config/environment - custom_logging: Custom effect with handler - early_return: Fail effect for clean error handling - effect_composition: Combining multiple effects - higher_order: Closures and function composition - pattern_matching: ADTs and exhaustive matching Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
30 lines
772 B
Plaintext
30 lines
772 B
Plaintext
// Prime number utilities
|
|
|
|
fn isPrime(n: Int): Bool =
|
|
if n < 2 then false
|
|
else isPrimeHelper(n, 2)
|
|
|
|
fn isPrimeHelper(n: Int, i: Int): Bool =
|
|
if i * i > n then true
|
|
else if n % i == 0 then false
|
|
else isPrimeHelper(n, i + 1)
|
|
|
|
// Find first n primes
|
|
fn findPrimes(count: Int): Unit with {Console} =
|
|
findPrimesHelper(2, count)
|
|
|
|
fn findPrimesHelper(current: Int, remaining: Int): Unit with {Console} =
|
|
if remaining <= 0 then ()
|
|
else if isPrime(current) then {
|
|
Console.print(toString(current))
|
|
findPrimesHelper(current + 1, remaining - 1)
|
|
}
|
|
else findPrimesHelper(current + 1, remaining)
|
|
|
|
fn main(): Unit with {Console} = {
|
|
Console.print("First 20 prime numbers:")
|
|
findPrimes(20)
|
|
}
|
|
|
|
let output = run main() with {}
|