What do you mean by a typed AST?

My point was that in the AST a function node accepts N polymorphic
sub-expressions (one for each argument). You cannot statically type the
number of arguments or the types of each argument as the language you are
compiling is not the same as the compilers host language, it requires
runtime checks.

So all nodes in my AST are subclasses of a generic AST node class, this is
no problem as the nodes need to be polymorphic anyway. We don't know until
runtime if a an abstraction will be in an application node etc (we do know
a var node is a leaf node). For an LR parser the stack is just a vector of
pointers to AST nodes (the base class of all AST nodes). Tree waking is
done using the visitor pattern, type-safely recovering the full type of
each node without casting.

In a functional language I would use a disjoint union for the node type (as
the tag in the disjoint union encodes the necessary runtime polymorphism).
To try and use types to encode this, where you are pushing runtime
polymorphism into the type system, and then to try and ignore that type
using a heterogeneous list (lime a list with existential type) seems
mistaken to me, when the fact is this is necessarily runtime polymorphism,
and that is most simply and directly encoded as a disjoint union type. You
gain nothing by trying to be tagless, as the type system will have to
insert hidden tags to recover the runtime polymorphism. It seems a classic
example of obfuscation by making things more complex than they needs to be,
when the simple solution is the right one.

Keean.
_______________________________________________
bitc-dev mailing list
bitc-dev@coyotos.org
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to