Repository navigation
Description
What you did
bend a.bend --check-only, then the same for b.bend and c.bend below. The syntax reference writes a do-block bind as x : A <- m and a let as x : A = v; each file leaves the : A off, the way a Haskell or Python user writes it the first time.
What happened
a.bend
SOME PROOFS FAIL
Error:
- expected : a defined name
- observed : x
Location: main
4 | do IO<Unit>:
5>| x <- IO.pure(U32, 1)
| ^
b.bend
SOME PROOFS FAIL
Error:
- expected : a pattern (a binder or a constructor)
- observed : {x : IO(Unit)}
Location:
4 | do IO<Unit>:
5>| x = 1
| ^
c.bend
SOME PROOFS FAIL
Error:
- expected : Type
- observed : U32
Context:
- n : U32
Location: f
None of the three mentions the annotation. a.bend says x is undefined, which sends the reader looking for a declaration of x; c.bend says a U32 was used where a Type goes, which has nothing to do with the bind; b.bend quotes a term the file does not contain. Adding : U32 after x (or n) makes each file check, and bend a.bend then prints 1.
The file
a.bend, a bind of a new name:
import Base
def main() -> IO(Unit):
do IO<Unit>:
x <- IO.pure(U32, 1)
IO.print(U32.show(x))b.bend, the same with a let:
import Base
def main() -> IO(Unit):
do IO<Unit>:
x = 1
IO.print(U32.show(x))c.bend, a bind of a name that already exists:
import Base
def f(n: U32) -> IO(Unit):
do IO<Unit>:
n <- IO.pure(U32, 1)
IO.print(U32.show(n))
def main() -> IO(Unit):
f(2)Expected
The cause is in parse_term_do_stmt (bend.ts:2248). The statement's first term is read with parse_term, and only a : after a variable makes the statement a bind or a let. So x <- m is read as the exec form A <- m with x as the type: for a new name that is "a defined name", for a U32 parameter it is a U32 where a Type goes. And x = v is read as the block's result {x : IO(Unit)}, after which the = has nowhere to go. The exec form itself is fine (Unit <- IO.print("a") and U32 <- IO.pure(U32, 1) both run); it is the lowercase name that gives the intent away.
When a statement is a bare name that is not a declared type, followed by <- or =, the error could say that the annotation is required, for example:
- expected : a typed bind (x : A <- m) or let (x : A = v)
- observed : x <- IO.pure(U32, 1)
That check would sit right after typed is computed, before parse_term reads the right-hand side, so an exec statement with a real type on the left keeps working.
bend version
bend 2.0.37, and main at 34003e6
uname -sm
Darwin arm64
clang --version (the first line)
Apple clang version 21.0.0 (clang-2100.3.34.2)
Activity
A do-block exec statement whose type is a lowercase name stays the ex…
A do-block bind or let without its type keeps its error and gains a note