lean4-htt/src/Lean/Compiler
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
..
IR feat: add withReader method 2020-10-13 15:00:17 -07:00
ClosedTermCache.lean chore: remove prelude commands from Lean package 2020-06-25 11:21:17 -07:00
ConstFolding.lean chore: remove prelude commands from Lean package 2020-06-25 11:21:17 -07:00
ExportAttr.lean feat: add Lean.MonadEnv, Lean.MonadError, and Lean.MonadOptions 2020-08-22 16:00:43 -07:00
ExternAttr.lean feat: improve extern arity calculation 2020-08-31 16:29:27 -07:00
ImplementedByAttr.lean fix: use resolveGlobalConstNoOverload at implementedBy attribute handler 2020-10-10 11:40:32 -07:00
InitAttr.lean fix: use resolveGlobalConstNoOverload at init attribute handler 2020-10-10 11:37:37 -07:00
InlineAttrs.lean feat: add Lean.MonadEnv, Lean.MonadError, and Lean.MonadOptions 2020-08-22 16:00:43 -07:00
IR.lean chore: remove prelude commands from Lean package 2020-06-25 11:21:17 -07:00
NameMangling.lean feat: expose mkModuleInitializationFunctionName 2020-09-21 08:53:29 -07:00
NeverExtractAttr.lean chore: remove prelude commands from Lean package 2020-06-25 11:21:17 -07:00
Specialize.lean fix: bad message 2020-09-25 18:48:23 -07:00
Util.lean fix: checkIsDefinition 2020-10-12 15:57:39 -07:00