Profile picture
Rob Rix‎ @rob_rix
, 7 tweets, 3 min read Read on Twitter
@a_cowley Pattern matching on the argument to the higher-order function is definitely a mistake, which PHOAS resolves by making it impossible. Learned that one the hard way!
@a_cowley Additionally, the basic treatment of it as e.g.:

data Expr = App Expr Expr | Lam (Expr -> Expr)

doesn’t really allow for free variables, which you often want—e.g. distinguishing locals, represented by variables in the metalanguage, from globals, represented as a constructor.
@a_cowley That can also be used to allow you to “quote” the thing back to a first-order representation, for equality tests, pretty-printing, etc. But I tend to use strings for var names in my term syntax, and then how do you know you’re not going to be clobbering other names?
@a_cowley 1. Lexical scoping means that’s not a problem unless/until you’re substituting in the first-order syntax, but substituting in first-order syntax has the usual capture avoidance challenges anyway; so why do it?
2. My Name datatype has a Gensym constructor so I can use Ints.
@a_cowley Finally, there’s the problem of actually constructing the things since you have to do so in pure code; (Expr -> Expr) doesn’t leave room for effects. So while my eval function runs in a Reader, it does the actual recursive evaluation in a pure function which it passes the env.
@a_cowley I also define substitution of globals in my HOAS Value type so that I can make, and then substitute, fresh names during unification, applying the higher-order functions to the fresh var, and then recovering a higher-order function by substituting the var with the arg.
@a_cowley Just about the only thing my current representation *doesn’t* offer is the ability to explicitly represent conflicts in the structure so I can easily do Elm-style type diffing for error messages. Thinking of doing this by splitting Expr into ExprF a and two different fixpoints.
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Rob Rix‎
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!