-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation: update language reference (#1829)
* Closes #1627
- Loading branch information
Showing
7 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
- [[./functions.md][Functions]] | ||
- [[./datatypes.md][Data types]] | ||
- [[./modules.md][Modules]] | ||
- [[./let.md][Local definitions]] | ||
- [[./control.md][Control structures]] | ||
- [[./comments.md][Comments]] | ||
- [[./axioms.md][Axioms]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
* Control structures | ||
|
||
** Case | ||
|
||
A case expression has the following syntax: | ||
|
||
#+begin_example | ||
case value | ||
| pat1 := branch1 | ||
.. | ||
| patN := branchN | ||
#+end_example | ||
|
||
For example, one can evaluate the following expression in the REPL: | ||
#+begin_example | ||
Stdlib.Prelude> case 2 | zero := 0 | suc x := x | _ := 19 | ||
1 | ||
#+end_example | ||
|
||
** Lazy builtins | ||
|
||
The standard library provides several builtin functions which are treated specially and evaluated lazily. These builtins must always be fully applied. | ||
|
||
- =if condition branch1 branch2=. First evaluates =condition=, if true evaluates and returns =branch1=, otherwise evaluates and returns =branch2=. | ||
- =a || b=. Lazy disjunction. First evaluates =a=, if true returns true, otherwise evaluates and returns =b=. | ||
- =a && b=. Lazy conjunction. First evaluates =a=, if false returns false, otherwise evaluates and returns =b=. | ||
- =a >> b=. Sequences two IO actions. Lazy in the second argument. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
* Local definitions | ||
|
||
Local definitions are introduced with the =let= construct. | ||
|
||
#+begin_example | ||
sum : NList -> Nat; | ||
sum lst := | ||
let | ||
go : Nat -> NList -> Nat; | ||
go acc nnil := acc; | ||
go acc (ncons x xs) := go (acc + x) xs; | ||
in | ||
go 0 lst; | ||
#+end_example | ||
|
||
The declaractions in a =let= have the same syntax as declarations inside a module, but they are visible only in the expression following the =in= keyword. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters