Closed joelburget closed 2 years ago
The obvious place to start would be replacing show with pretty in reduce. But why would a definition or native be reduced anyway? It's nonsensical.
We could simply throw an error on this and other Term
s for which a Term Name
is meaningless. The upshot would be we'd want top-level eval
to handle these and return the string stuff for use in the repl.
The upshot would be we'd want top-level eval to handle these and return the string stuff for use in the repl.
In the commit I just pushed I wasn't sure how to handle this. There are two cases to consider -- natives (eg +
) and definitions (eg yieldtest.tester
).
In the native case, things still work:
pact> +
native `+`
Add numbers, concatenate strings/lists, or merge objects.
...
This is because +
is represented as a TVar
, so reduce
just calls deref
, which returns the TNative
, which is pretty-printed.
In the definition case, we throw an error:
pact> yieldtest.tester
tests/pact/yield.repl:12:2: Unexpected evaluation of a definition (tester)
This is because (like in the native case) we're attempting to reduce a TVar
. This time however, we dereference the var and attempt to reduce it. Would it work for eval
to, when passed a var, first dereference it, check if it's a TDef
, and in that case, show the definition? This is a bit beyond my understanding of the evaluation mechanism.
@emilypi reported this bad error message:
The first thing to note is that pact thinks the module name is actually
"TDef {_tDef =..."
. How is this possible? Are you sure you want to know?The second clue is that
typecheck
is meant to be called with a string argument (eg(typecheck 'module)
). As an aside, this raises the question of how to typecheck qualified modules like Emily wanted to do. Is this possible? I don't know.Going to the definition of
typecheck
, we seedefZRNative "typecheck" tc ...
. The key is that we're defining it viadefZRNative
, which reduces all of its arguments. What doesreduce
do when passed aTDef
?So the module passed in is shown, resulting in the error message.
I don't know what the right fix for this is. The obvious place to start would be replacing
show
withpretty
inreduce
. But why would a definition or native be reduced anyway? It's nonsensical. We could changetypecheck
to not reduce its arguments, butreduce
changes types (reduce :: Term Ref -> Eval e (Term Name)
), so I'm not sure how to make this typecheck.