Skip to content

Commit e340a84

Browse files
author
Ryan Lahfa
committed
chore(docs/user): produce a simple Factorial example
I extracted a Factorial example in Rust to Lean. Signed-off-by: Ryan Lahfa <[email protected]>
1 parent 746b6d9 commit e340a84

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Base
2+
3+
/-!
4+
5+
# Computing factorial
6+
7+
-/
8+
9+
open Primitives
10+
set_option linter.dupNamespace false
11+
set_option linter.hashCommand false
12+
set_option linter.unusedVariables false
13+
14+
namespace factorial
15+
16+
/- [factorial::factorial]:
17+
Source: 'src/factorial.rs', lines 1:0-1:27 -/
18+
divergent def factorial (n : U64) : Result U64 :=
19+
if n = 0#u64
20+
then Result.ok 1#u64
21+
else do
22+
let i ← n - 1#u64
23+
let i1 ← factorial i
24+
n * i1
25+
26+
end factorial
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{#include factorial.lean}}

0 commit comments

Comments
 (0)