Commit graph

5796 commits

Author SHA1 Message Date
Leonardo de Moura
9af0a0e18b feat: add withReader method
@Kha `withReader` is a well-behaved version of `adaptReader`. `adaptReader` is
too general, and it often produces counterintuitive elaboration
errors.

Here are two super annoying issues I hit all the time:
1- `adaptReader` + polymorphic code
```
def ex1 : ReaderT Nat IO Unit :=
adaptReader (fun x => x + 1) $
  IO.println "foo" -- 3 Errors here failed to synthesize `Monad ?m` and  `MonadIO ?m`, and don't know how to synthesize `Type → Type`
```

2- `adaptReader` and notation that requires the expected type
```
structure Context :=
(x y : Nat)

def ex2 : ReaderT Context IO Nat :=
adaptReader (fun s => { s with x := 10 }) $ -- Error at the structure instance
  ...
```
In the example above, I have to write `fun (s : Context) => ...` to
fix the problem.

The two problems above happen in the old and new frontends. However,
there is a new problem specific for the new frontend. In the new
frontend, a `do` is only elaborated when the expected type is known.
So, `adaptReader (fun ctx => ...) do ...` seldom works :(

As I said above, the issue is that `adaptReader` is too general. Its
type is
```
  {ρ ρ' : Type u_1} → {m m' : Type u_1 → Type u_2} → [MonadReaderAdapter ρ ρ' m m'] → {α : Type u_1} → (ρ' → ρ) → m α → m' α
```

`withReader` is a simpler version of `adaptReader`
```
withReader : {ρ : Type u_1} → {m : Type u_1 → Type u_2} → [MonadWithReader ρ m] → {α : Type u_1} → (ρ → ρ) → m α → m α
```
It doesn't have any of the problems above. Moreover, I managed to replace
every single instance of `adaptReader` with `withReader` at the stdlib
and tests. We don't need the `adaptReader` generality.
2020-10-13 15:00:17 -07:00
Leonardo de Moura
d2e5c1c300 feat: improve dbgTrace! macro 2020-10-13 12:38:04 -07:00
Leonardo de Moura
d0bcb43c33 feat: improve Structural.lean 2020-10-12 16:58:30 -07:00
Leonardo de Moura
eacdb5ff83 feat: add Range notation 2020-10-12 11:50:13 -07:00
Leonardo de Moura
f57201d787 feat: add Repr and HasToString instances for PUnit and ULift 2020-10-12 11:01:59 -07:00
Leonardo de Moura
67e9c83f54 fix: for result type 2020-10-12 11:01:59 -07:00
Leonardo de Moura
dc670bfd5d fix: handle optParam at consumeImplicits
`consumeImplicits` is used during LVal resolution.
2020-10-11 15:26:10 -07:00
Leonardo de Moura
fda1d7b213 refactor: elabAppArgsAux
It also adds better support for opt/auto params and named arguments.
2020-10-11 15:08:12 -07:00
Leonardo de Moura
adc33da468 chore: $. and · 2020-10-11 15:08:12 -07:00
Leonardo de Moura
c5e3da89e8 fix: (try to) postpone when discriminant type is not known 2020-10-10 16:16:22 -07:00
Leonardo de Moura
7fec9587db fix: dollarProj notation bug 2020-10-10 13:38:07 -07:00
Leonardo de Moura
f84fa47566 fix: use resolveGlobalConstNoOverload at implementedBy attribute handler 2020-10-10 11:40:32 -07:00
Leonardo de Moura
89eebc9534 fix: use resolveGlobalConstNoOverload at init attribute handler 2020-10-10 11:37:37 -07:00
Leonardo de Moura
fa6b7b6393 feat: add MonadResolveName type class
`AttrM` can now resolve names.
2020-10-10 11:33:52 -07:00
Leonardo de Moura
63edecf106 feat: expand initialize macro 2020-10-10 08:23:49 -07:00
Leonardo de Moura
f80345a6d4 chore: move tests to new frontend 2020-10-10 07:41:04 -07:00
Leonardo de Moura
fb2fea2744 fix: explicit syntax kind in macro_rules 2020-10-10 06:42:45 -07:00
Leonardo de Moura
6a808540d5 chore: remove macro println! 2020-10-09 20:53:44 -07:00
Leonardo de Moura
9538772c1c chore: do not use string interpolation by default at dbgTrace!
It is nice to be able to write `dbgTrace! x` instead of `dbgTrace! "{x}"`
2020-10-09 20:49:39 -07:00
Leonardo de Moura
be252743b3 feat: add string interpolation for MessageData 2020-10-09 20:43:26 -07:00
Leonardo de Moura
b4ef8de1a5 test: new frontend tests 2020-10-09 18:21:45 -07:00
Leonardo de Moura
bca81714fe feat: println! and dbgTrace! macros with string interpolation 2020-10-09 17:19:04 -07:00
Leonardo de Moura
ef27af9cf8 test: string interpolation 2020-10-09 17:02:12 -07:00
Leonardo de Moura
51dc10dd93 feat: array slicing notation 2020-10-09 16:40:18 -07:00
Leonardo de Moura
5a40d9eb13 feat: add Subarray 2020-10-09 16:06:24 -07:00
Leonardo de Moura
749e2063cf feat: add interpolated string for toString 2020-10-09 14:38:24 -07:00
Leonardo de Moura
6020e6682a feat: process interpolatedStr in the elaborator 2020-10-09 14:18:45 -07:00
Leonardo de Moura
70ec458fde test: new frontend 2020-10-09 13:20:04 -07:00
Leonardo de Moura
650bd95ab9 feat: add efficient Array.forIn 2020-10-09 13:07:20 -07:00
Leonardo de Moura
0b81ffb569 refactor: factor out nested do term support and document code
We currently use the nested `do` terms for two combinators: `catch`
and `finally`. We may want to support more in the future.
2020-10-09 11:59:14 -07:00
Leonardo de Moura
f6fffc9532 test: monad stack with multiple ExceptT
cc @Kha :)
2020-10-08 19:53:12 -07:00
Leonardo de Moura
8a6cb1842f feat: expand doTry
@Kha I did not implement support for reassignments and `continue`,
`break`, `return` inside the `finally` clause. It is doable, but it
feels like unnecessary complexity. We currently don't have any
instance in our code base where this would be useful.
2020-10-08 19:39:36 -07:00
Leonardo de Moura
c005a9375a chore: remove workarounds 2020-10-08 16:50:59 -07:00
Leonardo de Moura
a31595bda5 feat: add doElem.quot elaboration function 2020-10-08 13:50:25 -07:00
Leonardo de Moura
a3a5190004 feat: expand doElem macros 2020-10-08 13:42:56 -07:00
Leonardo de Moura
608de7b592 feat: expand doReassignArrow 2020-10-08 13:31:27 -07:00
Leonardo de Moura
3694936b7d test: doHave test 2020-10-08 12:11:07 -07:00
Leonardo de Moura
09dcf718c1 feat: expand doHave 2020-10-08 11:56:03 -07:00
Leonardo de Moura
d7ec398b28 test: new do notation 2020-10-07 17:55:38 -07:00
Leonardo de Moura
91aaab9e0d fix: error message location 2020-10-07 17:43:23 -07:00
Leonardo de Moura
d9d8e95987 feat: elaborate doElems at doLetArrow
@Kha The Rust `let+return` example works in Lean too :)
The Rust function
```rust
fn f (x : i32) -> i32 {
    let y = if x == 0 { println!("x is zero"); return 100 } else { x + 1 };
    println!("y: {}", y)
    y
}
```
The Lean version is
```lean
def f (x : Nat) : IO Nat := do
let y ← if x == 0 then IO.println "x is zero"; return 100 else pure (x + 1)
IO.println ("y: " ++ toString y)
return y
```

The main missing feature now is the `try-catch-finally` `do` element.
2020-10-07 17:30:25 -07:00
Leonardo de Moura
ac07999e95 chore: cleanup do expander, and make sure it can handle the "easy" doLetArrows 2020-10-07 17:00:07 -07:00
Leonardo de Moura
5b76155318 feat: new return semantics
`return e` is not equivalent to `pure e` anymore.
Now, `return e` means "return value `e` as the result of the root `do` block".
2020-10-07 14:07:58 -07:00
Leonardo de Moura
e70dd03340 chore: remove forInMap 2020-10-07 10:01:04 -07:00
Leonardo de Moura
ac1c0714a1 fix: expand macros in patterns before retrieving pattern variables 2020-10-07 09:15:05 -07:00
Sebastian Ullrich
be7a3b76eb feat: Format.fill 2020-10-07 15:30:36 +02:00
Sebastian Ullrich
df16221013 fix: Format.be: properly re-evaluate flattening after hard line break 2020-10-07 11:03:44 +02:00
Sebastian Ullrich
f0dad079ad fix: checkWsBefore.formatter 2020-10-07 10:01:17 +02:00
Sebastian Ullrich
064c9b2e0b chore: binder spacing 2020-10-07 09:46:47 +02:00
Sebastian Ullrich
6c25717377 test: can finally reparse pretty-printed Core.lean 2020-10-07 09:46:47 +02:00