Commit graph

68 commits

Author SHA1 Message Date
Sebastian Ullrich
554d0b4d4c chore: adapt stdlib to new antiquotation splices 2020-12-12 17:20:03 +01:00
Sebastian Ullrich
f4267c9bf8 chore: revise Syntax.Traverser changes 2020-12-09 10:38:22 +01:00
Leonardo de Moura
702c258773 fix: index out of bounds
@Kha Please take a look at `Traverser` and check whether the
workaround is appropriate or not.
2020-12-08 11:44:10 -08:00
Leonardo de Moura
2120883307 refactor: heterogeneous operators
@Kha I had some unexpected surprises, but it is a good change.
Here is the summary.

1- We could get rid of `a %ₙ b` and `ModN` class. We can use `HMod`
instead. It was a positive surprise since I didn't remember we had
this `ModN` class.

2- Coercions are never used in heterogeneous operators. This is
expected since `a * b` is now notation for `HMul.hMul a b`, and
`a` and `b` may have different types. I manually added instances such
as `HMul Nat Int Int`. However, I did not try to add generic instances
such as
```
instance [Coe a b] [Mul b] : HMul a b b where
  hMul x y := mul (coe x) y
```
I will try later.

3- Give `h : cs.size > 0`, I got a type error at
```
let idx : Fin cs.size := ⟨cs.size - 1, Nat.predLt h⟩
```
`Nat.predLt h` has type `Nat.pred cs.size < cs.size`
However, `Nat.pred cs.size` doesn't unify with `cs.size - 1`.
The problem is that we can't synthesize the `HSub` instance until
we apply the default instances.
It worked before because `isDefEq` would force the pending TC
problem `Sub Nat` to be resolved, and after that we would be able
to reduce `cs.size - 1` and establish that it is definitionally
equal to `Nat.pred cs.size`.
I considered two possible workarounds
a) `let idx : Fin cs.size := ⟨cs.size - (1:Nat), Nat.predLt h⟩`
b) `let idx : Fin cs.size := ⟨cs.size - 1, by exact Nat.predLt h⟩`
The first one works because we are not providing enough information
for synthesizing the `HSub` instance. The second works because it
postpones the elaboration of `Nat.predLt h`. The default instances
will be applied before we start applying tactics.

4- The `.` notation is affected too. For example, `(x + 1).toUInt8`
doesn't work since we don't know the type of `x+1` until we apply
default instances. I fixed it by using `(x + (1:Nat)).toUInt8`.
Another possible fix is `Nat.toUInt8 (x + 1)`.
Similarly, `(x+1).fold ...` doesn't work.

5- The following code failed to be elaborated
```
indent (push s!"{ss'}\n") (some (0 - Format.getIndent (← getOptions)))
```
It was working before, but it relied on how the expected type is
propagated. The elaborator process
```
some (0 - Format.getIndent (← getOptions))
```
with expected type `(Option Int)`. So, the `-` is interpreted as
`Int.sub` although `Format.getIndent (← getOptions)` has type `Nat`.
In the new `HSub`, the expected type doesn't really influence TC
resolution since it is an `outparam`. So, we failed with the error
failed to synthesize `HSub Nat Nat Int`.
One possible fix was to add the instance `HSub Nat Nat Int` with
`Int.sub`, but I used the following fix
```
some ((0 : Int) - Format.getIndent (← getOptions))
```
which makes it clear that we want the `Int.sub` operator instead of
`Nat.sub`.
2020-12-01 14:02:46 -08:00
Leonardo de Moura
d734a2605b chore: adjust stdlib 2020-11-29 17:01:56 -08:00
Leonardo de Moura
9023e93b3e refactor: move Array.set to Prelude 2020-11-25 11:02:25 -08:00
Leonardo de Moura
d6f778bec4 refactor: arbitrary without explicit arguments
@Kha I was tired of writing `arbitrary _` :)
There 0 places in the stdlib where the type needs to be provided.
If in the future we need to specify the type we can use
`arbitrary (α := <type>)`
2020-11-25 09:07:38 -08:00
Leonardo de Moura
b72a3c69b6 fix: ambiguity at induction/cases
See efc3a320fe
2020-11-24 14:59:12 -08:00
Leonardo de Moura
29303f17f3 chore: test unboundImplicitLocals 2020-11-22 09:48:15 -08:00
Leonardo de Moura
304c80d610 feat: use <| 2020-11-19 09:03:38 -08:00
Leonardo de Moura
87d97c24a7 chore: code convention 2020-11-19 08:13:11 -08:00
Leonardo de Moura
7e533b4650 refactor: use Lists for Array reference implementation
Motivation: better reduction in the kernel.

cc @Kha
2020-11-17 17:05:53 -08:00
Leonardo de Moura
8c4ac7ccc1 refactor: rename LeanInit ==> Meta, and reduce dependencies 2020-11-13 16:00:31 -08:00
Leonardo de Moura
65dafaf07c fix: stdlib and tests
We also declare a few macros for the syntax command.
2020-11-12 07:12:30 -08:00
Leonardo de Moura
2537a2b84a chore: implement list and array literals using syntax command 2020-11-11 13:50:25 -08:00
Leonardo de Moura
cca3bad0bb feat: add Prelude.lean
`Prelude.lean` has no dependencies, and
at the end of `Prelude`, the `syntax` and `macro` commands are operational.
2020-11-10 18:08:18 -08:00
Leonardo de Moura
c665d5e20a chore: cleanup 2020-11-10 15:40:00 -08:00
Leonardo de Moura
2d2d39c78e chore: use mut 2020-11-07 17:32:13 -08:00
Leonardo de Moura
bf4d48f348 chore: cleanup for presentation 2020-11-05 12:43:02 -08:00
Leonardo de Moura
8c9f148e2f chore: use new termFor, termReturn, termTry, and tryUnless 2020-10-31 19:19:18 -07:00
Leonardo de Moura
131cb7036f feat: add combinators for Subarray 2020-10-28 19:49:38 -07:00
Leonardo de Moura
4ba21ea10c chore: cleanup src/Array/Basic.lean 2020-10-28 19:35:42 -07:00
Leonardo de Moura
6765440724 chore: remove clutter 2020-10-28 14:11:06 -07:00
Leonardo de Moura
3e6b2964cf chore: minor cleanup 2020-10-28 13:18:45 -07:00
Leonardo de Moura
898a08a0c1 chore: avoid Has prefix in type classes
closes #203
2020-10-27 18:29:19 -07:00
Leonardo de Moura
5fed774461 chore: HasRepr ==> Repr 2020-10-27 16:15:10 -07:00
Leonardo de Moura
10c32fcf94 chore: HasToString => ToString 2020-10-27 16:11:48 -07:00
Leonardo de Moura
13c2a8ff51 chore: remove #lang lean4 header 2020-10-25 09:54:07 -07:00
Leonardo de Moura
78c05e8f46 chore: move to new frontend 2020-10-23 16:13:55 -07:00
Leonardo de Moura
7030dc91f2 chore: move to new frontend 2020-10-23 12:50:03 -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
98f7e9b3e4 chore: naming convention 2020-09-24 19:22:24 -07:00
Leonardo de Moura
c46e64b089 feat: add Array.zipWith and Array.zip 2020-09-23 18:24:56 -07:00
Leonardo de Moura
ea2e86afba feat: add Array.allDiff 2020-09-08 16:16:14 -07:00
Leonardo de Moura
fc1e4cb533 feat: add Array.isPrefixOf 2020-09-08 14:40:43 -07:00
Leonardo de Moura
3ae3c51a8c feat: add Array.partition 2020-09-05 08:48:15 -07:00
Leonardo de Moura
0199e93079 chore: add Array.erase 2020-09-04 13:35:01 -07:00
Leonardo de Moura
3dbd2b728b feat: add Array.getMax? 2020-09-04 10:40:34 -07:00
Leonardo de Moura
47ff4d0e8e chore: add helper functions
TODO: we should `Subarray` and functions/methods for it. Then, we can delete
functions such as `foldlFromM`
2020-08-27 14:58:27 -07:00
Leonardo de Moura
bd8e2d305f feat: add Array.filterMap 2020-08-14 10:50:48 -07:00
Leonardo de Moura
81ae6a734b feat: mark List.toArray with [matchPattern] 2020-08-13 14:25:47 -07:00
Leonardo de Moura
aefc9a473f feat: add auxiliary definitions for compiling array literals in pattern matching expressions 2020-08-07 09:23:33 -07:00
Sebastian Ullrich
8f67db0101 refactor: never implicitly ignore monadic results
Also change `do e; f` to desugar to `e *> f` so that it is affected as well
2020-04-23 11:09:59 -07:00
Sebastian Ullrich
f66039f7f0 feat: generalize Array function universes 2020-04-06 13:48:09 -07:00
Leonardo de Moura
2d7ec0b49c fix: bug at unsafe umapMAux implementation
closes #125
2020-03-14 13:41:14 -07:00
Leonardo de Moura
6ad0c2cc18 feat: simplify unsafeCast 2020-03-14 13:10:56 -07:00
Leonardo de Moura
a0090b378b feat: move Array extensionality theorems to Init 2020-03-13 06:39:13 -07:00
Leonardo de Moura
a8c3322ac8 doc: expand dependent pattern matching support for array literals 2020-03-13 06:39:13 -07:00
Leonardo de Moura
50acb88727 feat: add auxiliary function for matching array literals 2020-03-11 11:57:01 -07:00