Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Abril <[email protected]>
  • Loading branch information
In-Veritas and Nicolas Abril authored Jan 17, 2025
1 parent 084e7ca commit be6662d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ You can bundle multiple values into a single value using a tuple or a struct.

```py
# With a tuple
def tuple_fst(x: Any) -> Any:
def tuple_fst(x: (a, b)) -> a:
# This destructures the tuple into the two values it holds.
# '*' means that the value is discarded and not bound to any variable.
(fst, *) = x
return fst

# With an object (similar to what other languages call a struct, a class or a record)
object Pair { fst, snd }
object Pair(a, b) { fst: a, snd: b }

def Pair/fst(x: Pair) -> Any:
def Pair/fst(x: Pair(a, b)) -> a:
match x:
case Pair:
return x.fst

# We can also access the fields of an object after we `open` it.
def Pair/fst_2(x: Paul) -> Any:
def Pair/fst_2(x: Pair(a, b)) -> a:
open Pair: x
return x.fst

# This is how we can create new objects.
def Pair/with_one(x: Pair) -> Pair:
def Pair/with_one(x: a) -> Pair(a, u24):
return Pair{ fst: x, snd: 1 }

# The function can be named anything, but by convention we use Type/function_name.
def Pair/swap(x: Pair) -> Pair:
def Pair/swap(x: Pair(a, b)) -> Pair(b, a):
open Pair: x
# We can also call the constructor like any normal function.
return Pair(x.snd, x.fst)
Expand Down
2 changes: 1 addition & 1 deletion docs/lazy-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

In strict-mode, some types of recursive terms will unroll indefinitely.

This is a simple piece of code that works on many other functional programming languages and hangs on strict-mode:
This is a simple piece of code that works on many other functional programming languages but hangs on Bend due to the strict evaluation of HVM2.

```rust
Cons = λx λxs λcons λnil (cons x xs)
Expand Down
4 changes: 2 additions & 2 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ For fields notated with `~` in the type definition, the fold function is called
It is equivalent to the inline recursive function:

```python
def fold(x: Tree) -> u24:
def fold(x: Tree(u24)) -> u24:
match x:
case Tree/Node:
return x.value + fold(x.left) + fold(x.right)
Expand Down Expand Up @@ -1357,7 +1357,7 @@ Documentation for functions is meant to be written as a multiline comment right

This function always returns the second value that was used as argument.
#}
def second(x: T, y: T) -> T:
def second(x: A, y: B) -> B:
return y
```

Expand Down

0 comments on commit be6662d

Please sign in to comment.