My thoughts on this were interrupted by Covid at a time when I was just beginning an experimental implementation.
As regards the implementation, automatic type annotations were only included to optimise the speed of type checking (not
to change the result) and could be dropped in these polymorphic cases without really showing much noticeable effect on the
system as a whole. The typechecker can find its own way there without misdirection. The simplest fix is to avoid misdirecting
automatic type annotations and this is easily done.
Having gone a bit deeper into the issue of the nature of ==> I've come to the conclusion that TBoS got it right in not making it primitive
because the effect of doing so has ramifications that are problematic. In particular YACC functions are always applied in the context
of the higher-order compile function as in (compile (fn <mycompiler>) something-or-other). The fn part is needed and then we are
in deep waters. fn is a shorthand for a lambda construction which in turn expands to (/. X (<mycompiler> X)) and the Rule of Applications
requires that <mycompiler> have the type (A --> B) for some A and B. Of course under the "==> is primitive" school it does not and so we are
faced with a major revision at the level of typed lambda calculus and this is definitely Not a Good Thing.
So TBOS made the right decision in making ==> syntactic sugar and leaving logical theory untouched and evolving an approach
that plugs into the existing theory and type checker.
Now as regards your implementation and the 3,000,000 inferences needed to certify the system; this is larger than I experienced
with a compiler for a subset of C (80,356 inferences for 515 lines of code). I think that this is probably a function of your type
theory rather than YACC and probably the fact that you are effectively defining the type of all symbolic expressions (from memory
of your program). I cannot run your program to see what is going on because you are using bespoke constructions. But from
experience the type of symbolic expressions often leads to exponential blowups. For example the expression [a b c] is a
symbolic expression but it is also a list of symbolic expressions.
Hence because of this type ambiguity, the type checker can assign a symbolic expression the wrong type and have to unpick this
decision later in the proof search. It is effectively working with a binary tree in terms of search and exponential blowups are common.
I'm not altogether unsurpised that you have a heavy overhead even though the speed of the typechecker under Scheme on my
computer would dispose of this in 1.5 seconds. It isn't a YACC problem specifically, but a problem with working with this particualr
type.
I'll put up a fix for misdirected type annotations which should not be hard.
Mark