Skip to content

Commit

Permalink
chore(docs/user): produce a simple Factorial example
Browse files Browse the repository at this point in the history
I extracted a Factorial example in Rust to Lean.

Signed-off-by: Ryan Lahfa <[email protected]>
  • Loading branch information
Ryan Lahfa committed Aug 20, 2024
1 parent 746b6d9 commit e340a84
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/user/src/lean/basics/factorial.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Base

/-!
# Computing factorial
-/

open Primitives
set_option linter.dupNamespace false
set_option linter.hashCommand false
set_option linter.unusedVariables false

namespace factorial

/- [factorial::factorial]:
Source: 'src/factorial.rs', lines 1:0-1:27 -/
divergent def factorial (n : U64) : Result U64 :=
if n = 0#u64
then Result.ok 1#u64
else do
let i ← n - 1#u64
let i1 ← factorial i
n * i1

end factorial
1 change: 1 addition & 0 deletions docs/user/src/lean/basics/factorial.lean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#include factorial.lean}}

0 comments on commit e340a84

Please sign in to comment.