Closed Toxaris closed 10 years ago
But then there's reify which currently returns Term. Of course, the result of reify should always be well-typed, but currently reify doesn't keep the type annotations, so reify cannot return a TypedTerm.
On this matter, we have discussed writing typedNbe
: in some situation we currently need some sort of "evaluator" which keeps type annotations, but we currently use typedSubst
which is less performant. (But in fact, typedNbe
evaluates "too much", which wastes work, though the result is still "correct".
Moreover, it performs unrestricted inlining, so that traversing the result might take exponentially more time. To avoid that, one needs an output normal form which allows for sharing — I've successfully used lets and A-normal form for this reason in my implementation of NbE in inc-lc/ilc-scala
.
Fixed by #106.
Fixed by #106.
AFAIK, without adding lets to reify, so maybe that's not even needed.
About the (still) missing sharing: The key is in this part of PTS.Dynamics.Evaluation:
close :: Name -> Value Eval -> Maybe C -> Value Eval -> Eval (Function Eval)
close name typ sort value = do
term <- reify value
abstract (\arg -> do
withEnvironment [] $ do
bind name (Binding False arg typ sort) $ do
eval term)
The potential problem is that term
is in normalform, so it might be huge, and then eval term
has to traverse this huge term.
We do lots of
strip
andreify
(insidenbe
), so maybe we should shuffle our use ofTerm
,TypedTerm
andValue
around. Also, we should more clearly state the invariants that come with these representations, and the pre- and postconditions of various functions.For example,
eval
takes aTerm
, but I think one shouldn't calleval
on an ill-typed term. So one should always calltypecheck*
first, getting aTypedTerm
and thenstrip
it again in order toeval
it. Maybeeval
should take aTypedTerm
then.But then there's
reify
which currently returnsTerm
. Of course, the result ofreify
should always be well-typed, but currentlyreify
doesn't keep the type annotations, soreify
cannot return aTypedTerm
.