
Higher-order abstract syntax - adamnemecek
https://en.wikipedia.org/wiki/Higher-order_abstract_syntax
======
fizixer
Based on my limited knowledge, SSA form is at a higher level than AST
(right?). If yes, would SSA be considered an example of HOAS?

Regardless, besides the question posed by OP, I wonder what the relation
between SSA and HOAS might be?

~~~
mafribe
ASTs and SSA are orthogonal concepts. ASTs are a representation of syntax
(including SSA) where immediate subterms are easily accessible (unlike with
strings as representation). Easy access to subterms is important for the
efficiency of type-checkers and code-generators. In contrast, SSA is a simple
programming language that is often used as an intermediate form in code
generators.

HOAS is a form of embedding a language L with binders into a language L-Base
also with binders and functions, but such that L-binders are handled by
functions in L-Base and the problem of defining capture-avoiding substitution
for L-terms is reduced to reusing L-Base's capture-avoiding substitution. (NB
L = L-Base is possible but not required.)

HOAS is neat, but (simplifying a bit) prevents you from making inductive
definitions on L terms. There are various ways of getting around this
shortcoming, the most principled one is probably the nominal approach of A.
Pitts et al. Another problem with HOAS is that the representation may contain
'junk'. That means there are L-Base terms that do not represent L-programs.

~~~
trurl
HOAS representations can only contain junk if you have not taken appropriate
precautions. See the paper "Boxes Go Bananas" for one technique.

~~~
mafribe
Yes, that's right. But you need parametric polymorphism for "Boxes Go Bananas"
which may not be available in some languages.

------
adamnemecek
I'd be very interested to hear opinions of people who've actually used this
and if so for what?

~~~
doomrobo
The Rust compiler uses DeBrujin indices to refer to variables at some point in
the compilation process.

~~~
tel
But that's pretty much exactly what HOAS is avoiding ;)

