louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#115 · main · 21 min 41 s
0Étoiles
0Forks
40Issues
| 1 | // Arithmetic through the `Num` trait (dictionary passing) and plain |
| 2 | // recursion. |
| 3 | |
| 4 | import std/io |
| 5 | |
| 6 | fn sum_to :: n: a i: a step: a acc: a -> a where Num<a>, Ord<a> |
| 7 | { |
| 8 | if i > n |
| 9 | { |
| 10 | acc |
| 11 | } |
| 12 | else |
| 13 | { |
| 14 | sum_to n (i + step) step (acc + i) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | fn fib :: n: Int -> Int |
| 19 | { |
| 20 | if n < 2 |
| 21 | { |
| 22 | n |
| 23 | } |
| 24 | else |
| 25 | { |
| 26 | fib (n - 1) + fib (n - 2) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | pub fn main :: -> () / <io> |
| 31 | { |
| 32 | io.println (show (sum_to 3000000 0 1 0) <> " " <> show (fib 30)) |
| 33 | } |
| 34 | //> 4500001500000 832040 |