lean4-htt/tests
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
..
bench chore: fix stdlib benchmark 2020-09-28 13:39:32 +02:00
compiler fix: handle optParam at consumeImplicits 2020-10-11 15:26:10 -07:00
elabissues chore: fix syntax 2020-05-21 09:57:35 -07:00
ir chore(tests): fix do syntax in tests 2019-06-30 13:04:34 +02:00
lean feat: add withReader method 2020-10-13 15:00:17 -07:00
playground feat: add ForInStep type 2020-10-03 15:16:45 -07:00
plugin chore: remove comment from Linter 2020-06-17 21:28:03 -07:00
.gitignore chore: move bin/ and .oleans into build directory 2020-05-14 14:47:54 +02:00
common.sh test: ignore \r when diffing 2020-09-15 09:32:00 -07:00