tobogganSe connecter

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.

34 lignes · 472 octetsBrut · Historique
1// Arithmetic through the `Num` trait (dictionary passing) and plain
2// recursion.
3
4import std/io
5
6fn 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
18fn 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
30pub fn main :: -> () / <io>
31{
32 io.println (show (sum_to 3000000 0 1 0) <> " " <> show (fib 30))
33}
34//> 4500001500000 832040