Commit Graph

745 Commits

Author SHA1 Message Date
Edwin Brady
87eeb200ce Add searchNames
Can now search for expressions by trying constructors
2019-05-04 19:19:22 +01:00
Edwin Brady
bfe78baf07 Add a 'staging area' to contexts
This is for updates we make while branching in an elaborator - we don't
want to update the context immediately, because if the branch fails,
we'll need to revert, so for safety we'll note the updates we're going
to make and only complete the update when we're back at the top level.
2019-05-03 02:43:47 +01:00
Edwin Brady
29a41ed975 Initial implementation of auto implicit search
This only searches for lambdas and locals so far, and doesn't take into
account that it shouldn't search for holes, but it does set up the basic
mechanism.
2019-04-27 20:18:53 +01:00
Edwin Brady
190690e925 Add namespaces for metavariable names
Since they're saved, they need to be unique across different input
files, so put them in a namespace. We might also add more metavariables
in the REPL, so save the name of the next variable in the current
namespace.
2019-04-26 16:33:06 +01:00
Edwin Brady
6d473014fd Add simple REPL for TTImp 2019-04-26 10:16:23 +01:00
Edwin Brady
e592f548d1 Add timing logs
Just to allow tracking how long individual parts of processing a file
take!
2019-04-25 23:43:19 +01:00
Edwin Brady
762f6010dd Basic TTC saving and loading now works
Only save the parts of terms and definitions which are needed for
typechecking and evaluation (so, for example, we don't need types for
machine generated metavariables, don't need types on lambdas, etc).
2019-04-25 14:46:36 +01:00
Edwin Brady
a48d90f821 More progress on TTCs
Added Core.Directory (more or less directly from Blodwen) and now
writing out TTCs from the test Main, but it's still not writing out
definitions because we're not yet making a note of the names which need
saving (this will be the defined names and any holes introduced).

Also it's clear from logging that holes/guess/constraints aren't being
cleared so this needs to be fixed next.
2019-04-21 23:20:10 +01:00
Edwin Brady
bc26d74f9b Deal with unresolved constraints
Well-typed interpreter example now works (added in samples)
2019-04-20 22:00:58 +01:00
Edwin Brady
63da191e03 FOUR!!!1!!!
Er, that is to say, evaluation of a 'main' expression
'plus (S (S Z)) (S (S Z))' is now printing the right answer.
2019-04-20 16:54:09 +01:00
Edwin Brady
34bf6651a9 Progress on CaseBuilder
Mostly this is being copied from Blodwen, with an additional case for
dealing with 'as' patterns more nicely. Still some bits to do to finish
it off though.
2019-04-20 15:14:07 +01:00
Edwin Brady
dc3c0da2a0 Build patterns from closed terms
We'll use fresh names for the variables in the environment, then
recalculate the local variables as we build the case tree (we don't know
how many we'll need in advance, especially given 'as' patterns)

Also implement 'subst' for this (it may turn out to have other uses too)
2019-04-19 22:46:41 +01:00
Edwin Brady
82ac86bde0 Replace 'Fn' with 'PMDef'
Pattern matching clauses rather than just simple terms
2019-04-19 21:50:23 +01:00
Edwin Brady
cd958bd304 Remove 'Case' from Term structure
It seems that this isn't going to buy us enough to be worth the
complications of compiling case trees, dealing with 'with' etc.
2019-04-19 20:10:55 +01:00
Edwin Brady
0c7ef9bbac Calculate linearity of variables on LHS 2019-04-19 16:35:06 +01:00
Edwin Brady
01572ec47a Check RHS and build PatAlt
We need to be able to convert function arguments into Pats for this, and
so this also adds cases to Pat for matching on constants and types.
2019-04-19 16:06:26 +01:00
Edwin Brady
c3f36ce484 Add IBindHere for type declarations
This means we have unbound implicits in types now
2019-04-18 17:24:56 +01:00
Edwin Brady
c41ab9778f Progress towards pattern matching
Checking IBindVar and IBindHere, and first check of left hand side with
implicitly bound pattern variables.
2019-04-18 14:51:04 +01:00
Edwin Brady
e8e39524a0 Delay elaborating args when return type known
We do this because, working left to right, if there's an implicit
argument we won't necessarily know the types of later arguments before
elaborating them. But, since we want to have type directed
disambiguation of names, it's better to learn the values of those
implicits from the return types than from the elaboration of the later
arguments, because then we'll be able to use that type to help
disambiguate later arguments if necessary.
2019-04-14 16:48:21 +01:00
Edwin Brady
41627b99c4 Add some combinators for backtracking
Since the context is mutable state, we need to record changes (that's
basically the variables we've solved and the next name id to use) and
undo them one by one. So this will make backtracking potentially a
little bit expensive, but at least the updates are constant time!
2019-04-13 22:28:48 +01:00
Edwin Brady
9611431260 Refine order of elaboration of arguments
If an argument's type isn't known (i.e. it's still a metavariable) make
a hole for it, and delay its elaboration until the other arguments have
been elaborated.
This is to help type-directed disambiguation (so we know as much as
possible about the target type before elaborating an argument).
2019-04-13 19:37:53 +01:00
Edwin Brady
9e7e27ed03 Fill in holes for reading/writing TTC
Tricky bit is the 'NameRefs'. When we load a file back in, we load a
mapping from resolved ids in the file to their full names, and
immediately resolve them in the current context so that we have the
correct ids after loading.
2019-04-13 13:33:45 +01:00
Edwin Brady
e2594e9c80 Make a start on TTC reading/writing 2019-04-07 21:12:04 +01:00
Edwin Brady
56a2f98488 Implement data forward declarations
This is the last hole to fill in (for the moment!)
2019-04-07 17:24:37 +01:00
Edwin Brady
56c0ec5324 Implement inferLambda
This checks lambdas where the type isn't immediately a pi binder. First
normalises, if that doesn't work, just guesses and unifies with the
expected type.
2019-04-07 17:16:44 +01:00
Edwin Brady
b8595eef8b Fill in some holes
The 'case' case of mkLocals, and looking up types of primitive constants
2019-04-07 14:51:50 +01:00
Edwin Brady
968b48c96e Some optimisations
Hole list represented as a map now for quicker deletion of solved holes.
Unification returns whether it solved any holes as part of its result,
so we know if it's worth going back to solve constraints if progress has
been made.
2019-04-07 11:50:36 +01:00
Edwin Brady
947e33cc97 Initial implementation of data types 2019-04-06 22:40:15 +01:00
Edwin Brady
10b1b6eb8d Unifying pi binders, add implicit lambda 2019-04-06 17:37:20 +01:00
Edwin Brady
3cd09bb6a8 Unification infrastructure all done
Can instantiate metavariables, although there's a lot of cases still to
deal with
2019-04-06 13:53:59 +01:00
Edwin Brady
8b98a5cb99 Some unifiation infrastructure 2019-03-28 11:04:18 +09:00
Edwin Brady
6174acc52a Progress on elaborator
Changed 'check' so that it returns the type as a 'Glued', which is a
pair of a term and its normalised form (or, more accurately, the process
to generate each in Core). Sometimes the elaborator needs Term,
sometimes in needs NF; this way we can return both but only actually
generate it when its needed.

So far, mostly done applications, binders and variables. Unification is
still to do.
2019-03-23 18:13:49 +04:00
Edwin Brady
547eea953c A bit of reorganisation
Better to have the elaborator across multiple files, for ease of
navigation. Also abandon the idea of local unification variables -
we'll keep them global, and try let binding them on leaving a scope.
2019-03-18 16:25:53 +00:00
Edwin Brady
7d672407c8 Start on UnifyState
Also removed 'MV' as a special name type, and added a Meta constructor
in TT which is applied to exactly the right number of arguments for the
environment the meta was constructed in.

It's possible the local unification UCtxt may be more trouble than it's
worth! Instead perhaps we can try let binding unification solutions where
possible on leaving the scope in which they're introduced.
2019-03-17 20:43:51 +00:00
Edwin Brady
57f1fb77c3 Added 'quick' unify
Unification based only on constructor arguments and matching - anything
else fails. Idea is to solve 'easy' local unification problems quickly,
without having to create a global metavar applied to the current context.
2019-03-17 13:34:22 +00:00
Edwin Brady
b4be370213 Add conversion check 2019-03-16 17:35:18 +00:00
Edwin Brady
4951daa3df Start on conversion 2019-03-16 16:52:01 +00:00
Edwin Brady
7b170ca797 Initial implementaiton of evaluator 2019-03-16 15:26:14 +00:00
Edwin Brady
1cbbd39327 Finish thin/weaken for Terms 2019-03-10 23:51:41 +00:00
Edwin Brady
23051a55de Add Weaken interface, to start evaluator 2019-03-10 22:00:10 +00:00
Edwin Brady
0f8d337b27 Add a main program which processes a source file 2019-03-10 18:20:26 +00:00
Edwin Brady
992d8dd0f9 Added parser for most basic terms
Just variables, binders, applications, and basic declarations (data,
type and function definitions)
2019-03-10 17:56:08 +00:00
Edwin Brady
e03a2ba4b5 Added context for global names, store in an array 2019-03-10 15:14:38 +00:00
Edwin Brady
77e634cd33 Add specialised maps for Int and Name
The repetition is unfortunate, but worth it for avoiding the overhead of
passing an Ord dictionary around
2019-03-07 23:29:03 +00:00
Edwin Brady
082bc5cd54 Initial structure
TT types and values, some text manipulation, basics of Core
2019-03-07 23:04:55 +00:00