Commit Graph

122 Commits

Author SHA1 Message Date
Edwin Brady
0bb9a13d37 Update method names when checking default methods
Fixes #42. If we don't do this, the name is treated in the saem way as
an unbound implicit, which is not what we want, so update with the
method applied to the parameters.
2019-07-27 17:01:02 +01:00
Edwin Brady
f6fa192779 Add test for fix for #49 2019-07-26 23:13:11 +01:00
Edwin Brady
fa76f2a78b Bind auto implicit arg names in LHS
We were only doing implicits, so add auto implicits too. It's slightly
tricky, because we might also have implicits given of the form @{x}
which stands for the next auto implicit.

Fixes #50
2019-07-26 16:58:02 +01:00
Edwin Brady
8e9655dd9b Unbound implicits are invertible in terms
Just like all other pi-bound things, if m is an unbound implicit and we
have m ?x = m y as a unification problem, we can conclude ?x = y because
it has to be true for all ms.

This was implemented in Blodwen but I hadn't got around to it yet for
Idris2... fortunately it's a bit easier in Idris2!

Fixes #44
2019-07-26 12:27:54 +01:00
Edwin Brady
86eb475413 Check for name clashes in impl constraints
We were only checking parameters, meaning that there were potential
clashes leading to confusing behaviour, and meaning that it was somehow
relevant what the names were in the interface!
2019-07-22 23:16:51 +01:00
Edwin Brady
7e67ba4f35 Allow marking interface methods multiplicities
Now by marking a method as multiplicity 0, we can explicitly say that
it's compile time only, so we can use it to compute types based on other
erased things - see tests/idris2/interface008 for a small example.

This fixes #8 - at least in that it allows the interface to be expressed
properly now, although the multiplicity annotations mean that
unfortunately it can't be compatible with Idris 1.
2019-07-22 16:21:33 +01:00
Edwin Brady
91262b4800 Fix possible loop in auto implicit search
A local variable can't be applied to itself when searching (otherwise,
for example, we could end up trying something like id id id id id id etc
forever). So remove it from the environment before searching for its
arguments.

This and the previous patch fix #24. (Or, at least, the minimised cases
reported as part of it!)
2019-07-22 11:21:34 +01:00
Edwin Brady
6d90b72fe9 Check under data constructor for holes
We can't begin a search until we know what we're searching for! For some
reason I forgot to add this case, and without it the search space can
explode, or we might find an answer too soon and commit to the wrong
thing!

Fixes #36
2019-07-20 21:09:33 +01:00
Edwin Brady
0b1d6527c8 Add test for #25 2019-07-20 19:01:34 +01:00
Edwin Brady
cae9162fcf Check under 'as' patterns for case arg usage 2019-07-20 18:57:03 +01:00
Edwin Brady
6dd18d798a Allow annotating functions with multiplicity
This means we can write truly type level only functions, by annotating
them with a 0 before the type declaration.
2019-07-20 18:04:18 +01:00
Edwin Brady
607e280895 Place implicits through to method bodies
This means that even if the relevant parameters aren't used by a method
body, the method can still see what the implicits are (though they will
be 0 multiplicity).

This is relevant to #8, but doesn't really fix it because we still need
a way of saying that methods are 0 multiplicity.
2019-07-20 16:25:40 +01:00
Edwin Brady
9f94606037 Finish Chapter 12 tests 2019-07-12 09:34:29 +02:00
Edwin Brady
39ee4ad9c8 Numeric range syntax 2019-07-12 09:32:36 +02:00
Edwin Brady
4860d2b751 Add Range interface to prelude
This is part of what we used to have in Enum but I think it's better to
separate the two. Added implementations for Nat, and anything in
Integral/Ord/Neg, so that we get range syntax (at least when its
implemeted) for the most useful cases.
2019-07-11 23:38:25 +02:00
Edwin Brady
1cf9849a55 Add the bits of Chapter 12 that work
Still need enumeration syntax for the rest
2019-07-10 20:22:00 +02:00
Edwin Brady
fd4f90e331 Add some Control.Monad things
This required a small change to auto implicit search (and I'm still not
sure about this). Now search arguments right to left, because solving
later arguments may resolve earlier arguments by unification and this
can happen in particular when chasing parent interfaces (which may have
fewer parameters).
2019-07-10 20:18:40 +02:00
Edwin Brady
9f6a3fd2b8 Fix in scheme backend and test script
At least on Linux, \r needs to be in singles quotes as an argument to tr
or it removes all the 'r' instead! Hopefully it also works this way on
Windows...
2019-07-10 17:23:45 +02:00
Edwin Brady
a422294f36 Pass auto implicits through interfaces
This allows 'traverse' to work now (it was treating them as normal
implicits, so building the wrong form of application)
2019-07-10 17:23:33 +02:00
Niklas Larsson
28438650d0 windows support 2019-07-10 01:51:41 +02:00
Edwin Brady
2487c30232 Adding missing test files 2019-07-09 09:22:50 +02:00
Edwin Brady
2bb496f74b Chapter 11 examples now working 2019-07-08 23:46:20 +02:00
Edwin Brady
164a0a60cf Add Chapter 10 TypeDD tests
A lot to change here! To be honest, this chapter probably needs a
complete revision...
2019-07-08 13:04:39 +02:00
Edwin Brady
11199acab6 Improve 'with' implementation
Now supports with applications on the RHS when auto implicits are
involved. Auto implicit bound names in patterns now become searches on
the rhs in a with-application (I should write this construct up properly
in a paper some time!)
2019-07-08 12:55:55 +02:00
Edwin Brady
51c406ff7d Deal with non-existent files more gracefully
So now you can start idris2 with a non-existent file and use :e to start
editing it
2019-07-07 13:10:14 +01:00
Edwin Brady
fc224b1450 Fix Total004 test
Names in Data.List clashed
2019-07-06 15:55:47 +01:00
Edwin Brady
4ab543b83d A bit more library support, for Chapter 9
Also a tweak to errors when compiling to scheme, so that it properly
reports an error then quits if it's supposed to crash.
2019-07-05 17:24:15 +01:00
Edwin Brady
5fc0aa8248 Add Chapter 8 tests 2019-07-05 11:28:37 +01:00
Edwin Brady
7c34fa1db4 Change equality elaboration
Elaborate via either === (homogeneous equality) or ~=~ (heterogeneous
equality) both of which are synonyms for Equal. This is to get the Idris
1 behaviour that equality is homogeneous by default to reduce the need
for type annotations, but heterogeneous if that doesn't work.
2019-07-05 11:26:45 +01:00
Edwin Brady
40d9235b3f Allow ambiguity when chasing parent interfaces
There's a bit of a trade off here. It would be better to report the
ambiguity but this would lead to a need for (I think) excessive
precision in types which would impact usability. It will always take the
leftmost interface.

Chapter 7 tests added.
2019-07-05 10:29:41 +01:00
Edwin Brady
aa58114671 Add 'last chance' unification and tweak guesses
Idris 1 will fill in the last metavariables by matching rather than
unification, as a convenience. I still think this is okay, even if it's
a bit hacky, because it's a huge convenience and doesn't affect other
unification problems.

Also abstract over lets in guesses, like in delayed elaborators, to
avoid any difficulties when linearity checking and to make sure that let
bound things don't get reevaluated.

This is enough to get the Chapter 6 TypeDD tests working
2019-07-05 00:09:00 +01:00
Edwin Brady
c260f6c90e Improve dot patterns
Allow matching rather than unification, as long as it doesn't solve any
metavariables on the way. I noticed a potential unification bug on the
way, forgetting to update whether holes are solved when unifying
argument lists.
2019-07-04 23:16:08 +01:00
Edwin Brady
6f5d3f5fef Unelaborate hole applications properly
This was left over from Blodwen (where it was also wrong :)) but the way
we apply metavariables now means we don't need to do anything fancy when
unelaborating them for pretty printing.
2019-07-03 15:31:46 +01:00
Edwin Brady
89c8314a0f Desugar pattern matching lambdas 2019-07-03 15:11:57 +01:00
Edwin Brady
0f56c239c2 Parse pattern matching lambda
This is now enough for Chapter 5 tests to work
2019-07-03 13:04:25 +01:00
Edwin Brady
e526badfe2 Delay case elaboration
This helps a few things because it delays elaboration of the block until
as much as possible is known about its type.

Also added a few libraries.
2019-07-02 16:53:41 +01:00
Edwin Brady
5eec46f6ce TypeDD chapter 4 tests 2019-07-01 21:35:19 +01:00
Edwin Brady
00514887c4 More base libraries
This has shown up a problem with 'case' which is hard to fix - since it
works by generating a function with the appropriate type, it's hard to
ensure that let bindings computational behaviour is propagated while
maintaining appropriate dependencies between arguments and keeping the
let so that it only evaluates once. So, I've disabled the computational
behaviour of 'let' inside case blocks. I hope this isn't a big
inconvenience (there are workarounds if it's ever needed, anyway).
2019-06-30 23:54:50 +01:00
Edwin Brady
577b68dd5a Make a start on Data.Vect 2019-06-30 17:38:40 +01:00
Edwin Brady
f2dff5cae4 Normalise holes in error messages
The solved holes may not outlive the error, so normalise before throwing
so that they can be displayed properly.
2019-06-30 17:23:19 +01:00
Edwin Brady
f37da6c5b7 Start adding tests for TypeDD book
Also detailing any changes needed to the code. Added primitives for
Doubles, and repl/replWith to get Chapter 2 code to work.
2019-06-30 15:50:58 +01:00
Edwin Brady
eddb23d108 Need to save postponed names in ttc too
Flag these when searching names for references
2019-06-30 12:49:11 +01:00
Edwin Brady
ae777b8dcb Add parameters blocks 2019-06-29 23:55:17 +01:00
Edwin Brady
2f4cdf857d Make typecase on -> work 2019-06-29 22:43:06 +01:00
Edwin Brady
17c862fe00 Add parse error tests from Blodwen 2019-06-29 21:37:30 +01:00
Edwin Brady
f9ea1ff329 Updating typecase, add tests 2019-06-29 21:32:19 +01:00
Edwin Brady
7aa8a71f8f Fix loading of hints, and add test
Need to add by full name, due to ordering of loading (the name it's
attached to may not be resolved yet!). This doesn't seem to cause any
performance problems but we can revisit if it does.
2019-06-29 20:51:48 +01:00
Edwin Brady
e463a2864a Add a couple more tests 2019-06-29 20:03:00 +01:00
Edwin Brady
a65d1efa38 Throw error if case type is not inferred
This is probably quite rare to want, but we could consider putting this
under a delayOnFailure
2019-06-29 19:39:11 +01:00
Edwin Brady
99dac56e1e Make sure matches are not too specific
i.e. if an argument has a polymorphic type, we shouldn't allow a
concrete type in its place
2019-06-29 19:28:04 +01:00