Commit graph

1365 commits

Author SHA1 Message Date
Leonardo de Moura
fac2849e50 feat: forIn for PersistentArray 2020-10-20 09:33:50 -07:00
Leonardo de Moura
7bfa39ae45 fix: for .. in .. do notation and universe constraints
We use `MProd` instead of `Prod` to group values when expanding the
`do` notation. `MProd` is a universe monomorphic product.
The motivation is to generate simpler universe constraints in code
that was not written by the user but generated by the `do` macro.
Note that we are not really restricting the macro power since the
`HasBind.bind` combinator already forces values computed by monadic
actions to be in the same universe.

The new test cannot be compiled without this modication.
2020-10-18 18:05:00 -07:00
Leonardo de Moura
e3e89b4945 chore: add coercion for new frontend 2020-10-16 15:39:00 -07:00
Leonardo de Moura
dd4ae81774 chore: move to new frontend 2020-10-16 09:16:33 -07:00
Leonardo de Moura
e02a06ad1c chore: move to new frontend 2020-10-16 08:40:42 -07:00
Leonardo de Moura
54c1607b36 chore: export Name.eraseMacroScopes 2020-10-15 11:35:32 -07:00
Sebastian Ullrich
5a21725d69 perf: avoid String.toList 2020-10-15 19:43:13 +02:00
Leonardo de Moura
c1dccb8154 feat: stx[i] as notation for stx.getArg i 2020-10-13 15:48:39 -07:00
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
9204b4cc2f chore: missing specialize 2020-10-12 12:11:17 -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
Sebastian Ullrich
8b62665788 chore: print dbg* output to stderr 2020-10-12 10:01:29 +02:00
Leonardo de Moura
7c6b10012b chore: add helper function 2020-10-11 19:58:07 -07:00
Leonardo de Moura
8555cbaace fix: export command for new frontend 2020-10-11 19:44:43 -07:00
Leonardo de Moura
6a808540d5 chore: remove macro println! 2020-10-09 20:53:44 -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
51dc10dd93 feat: array slicing notation 2020-10-09 16:40:18 -07:00
Leonardo de Moura
3bd75d51d5 feat: add ParserDescr.noWs 2020-10-09 16:26:49 -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
7013ea4098 feat: add interpolatedStr to ParserDescr and Syntax 2020-10-09 14:04:53 -07:00
Leonardo de Moura
36696d726d feat: add String Interpolation 2020-10-09 13:40:35 -07:00
Leonardo de Moura
650bd95ab9 feat: add efficient Array.forIn 2020-10-09 13:07:20 -07:00
Leonardo de Moura
7574b9f0ef feat: add coercion Fin => Nat 2020-10-09 12:22:04 -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
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
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
98dbe45ab8 chore: remove Monad List instance
@Kha The new `do` notation works for pure code too.
It automatically inserts `Id` if the expected type is not a monad.
This works great when we are not conflating data and control.
After deleting `Monad List`, we will be able to write functions such as
```lean
def mapWhen (p : Nat → Bool) (f : Nat → Nat) (xs : List Nat) : List Nat := do
for x in xs do
  if p x then
    x := f x
```
without adding `Id.run` before the `do`.
2020-10-05 13:27:18 -07:00
Leonardo de Moura
5adb04b10e chore: add helper instance 2020-10-05 11:24:35 -07:00
Leonardo de Moura
82e11c401d fix: #eval was not capturing dbgTrace! output in pure code
In the following example, the output produced by `dbgTrace!` was not
being captured. It could break the lean server. At least, it broke the lean4-mode.
```lean
def f (x : Nat) : Nat :=
dbgTrace! ">>> " ++ toString x;
x + 1

eval f 10
```

cc @Kha
2020-10-05 10:22:04 -07:00
Leonardo de Moura
d7d7e16f96 chore: Id missing instances 2020-10-05 09:55:19 -07:00
Leonardo de Moura
b4289d5c5d feat: add DoResult 2020-10-03 15:38:30 -07:00
Leonardo de Moura
21d90afa43 feat: add ForInStep type 2020-10-03 15:16:45 -07:00
Leonardo de Moura
0911b9bc80 feat: add missing features to do notation parser 2020-09-30 06:51:25 -07:00
Sebastian Ullrich
16c71e6a26 fix: IO.Process.output 2020-09-29 08:01:10 -07:00
Sebastian Ullrich
ab6b6ac3ba feat: add dedicated task priority 2020-09-29 08:01:10 -07:00
Sebastian Ullrich
562c7ed5ce feat: expose task priorities 2020-09-29 08:01:10 -07:00
Leonardo de Moura
3f4499be08 feat: allow trailing ; at doSeqBracketed 2020-09-26 14:20:47 -07:00
Sebastian Ullrich
eae32b08a6 fix: pretty printing multiple universe levels
Fixes #190
2020-09-25 20:06:18 +02:00
Leonardo de Moura
98f7e9b3e4 chore: naming convention 2020-09-24 19:22:24 -07:00
Leonardo de Moura
550b5d2b47 chore: missing [inline] 2020-09-24 12:40:28 -07:00
Leonardo de Moura
c46e64b089 feat: add Array.zipWith and Array.zip 2020-09-23 18:24:56 -07:00
Leonardo de Moura
241eabfc41 fix: non termination on ill-formed string literals 2020-09-20 17:05:18 -07:00
Leonardo de Moura
f679b7d803 feat: add notFollowedBy to syntax 2020-09-19 15:43:44 -07:00
Leonardo de Moura
3e9b2a0b08 feat: add expandMacro? and expandMacros methods to MacroM 2020-09-19 13:02:27 -07:00
Leonardo de Moura
7b6d06df0d fix: remove bad instances
They are unnecessary, and were producing a very big search space in a
few examples.
2020-09-17 17:31:09 -07:00
Leonardo de Moura
f4aabaecae refactor: move Lean.quote to LeanInit
cc @Kha
2020-09-17 08:15:58 -07:00
Leonardo de Moura
18a7f5a489 feat: new name sanitizer 2020-09-16 11:57:55 -07:00