1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-14 08:27:03 +03:00
juvix/tests/positive/Symbols.juvix
Łukasz Czajka df4187a25f
Improve error message for confusing ':=' with '=' (#1715)
Closes #1483 

The error now points to the offending `=`, works correctly with
multi-line clauses, and explains exactly what's wrong. E.g. for
```agda
f : Nat → Nat → Nat;
f zero x = x;
```
we get
```
  |
6 | f zero x = x;
  |           ^
expected ":=" instead of "="
```
A minor disadvantage of the proposed solution is that now it's
impossible to use `=` without parentheses as a top variable name in a
pattern, e.g.
```
f zero = := =;
```
gives an error.

However, if one really wants to name a variable `=`, it is enough just
to enclose it in parentheses:
```agda
f : Nat → Nat → Nat;
f zero (=) := =;
f (suc n) (=) := f n =;
```

I believe this slight non-uniformity is well worth the increased
usability due to a better error message. Confusing `:=` with `=` is very
common. Using `=` as a variable name in a top pattern is rare.

Co-authored-by: janmasrovira <janmasrovira@gmail.com>
2023-01-11 16:43:16 +01:00

37 lines
590 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module Symbols;
open import Stdlib.Data.Nat;
╘⑽╛ : Nat;
╘⑽╛ := suc nine;
-- no - function!?
- : Nat -> Nat -> Nat;
- := (+);
- : Nat -> Nat -> Nat;
- := (-);
* : Nat -> Nat -> Nat;
* := (*);
infixl 6 ;
: Nat -> Nat -> Nat;
:= -;
infixl 7 ·;
· : Nat -> Nat -> Nat;
· := *;
0 : Nat;
0 := ╘⑽╛ ╘⑽╛ · zero;
主功能 : Nat;
主功能 := 0;
axiom = : Type;
K : Nat → Nat → Nat;
K =a@zero (=) := =a · =;
K =a@(suc =) == := = · ==;
end;