Maybe I'm getting mixed up between 'environments' and 'contexts' too - I was attempting to use the typechecking context to do my substitutions, but it's obvious now that it that would break down in more complex examples. In HOAS you get an environment for free.
Conversation
AFAIU: context = name -> type, env = name -> value. And the diff between "normalization" and "evaluation" is more-or-less that normalization goes under binders and "fully evaluates" (to "*the* normal form"), mere 'evaluation' doesn't (necessarily).
1
1
1
(Once again I'm trying to relay things I learned from András, most likely imperfectly.)
1
(I'm also not -certain- HOAS couldn't work in Rust - do you _need_ to use Rc everywhere, can't you use &Fn during the normalization process? I might experiment a little...)
1
1
Very possibly! Would love to see a quick gist!
1
Here's a start on the Wikipedia example of NbE: play.rust-lang.org/?gist=e6e7d13c - note how you need to allocate the closures at some stage. I guess you could allocated them in an arena or something? 🤷♂️
1
1
Heh. I haven't done very much actual coding in Rust so I started with a typechecker (because that's more obvious) just to re-familiarize myself before attempting that: play.rust-lang.org/?gist=e75c0f71
1
(incidentally, if you know how to make the ugly parts of that (e.g. (*foo).clone()) less ugly, i'd be curious)
(haven't looked at yours in detail yet because bbiab:)
1
I just use Rcs for all the nodes. Might switch to an arena at some stage though. Feel free to check out Pikelet if you like - it does get a little icky at times, alas.
1
Here's some cleanups I would make at least - strategically choosing match vs if let can make things cleaner: play.rust-lang.org/?gist=45361c3a - also tend to fully qualify variants. That way I don't need to do things like TFunction etc.
1
Also the direct approach of matching and using ? looks cleaner in Rust and formats better than using monadic combinators. Sometimes they do help, but I just tend to use them more sparingly these days.
Thanks! The bit w.r.t. using `match` to avoid `**` is nice. W.r.t. some of the others I started writing it that way then thought better of it, or couldn't resist golfing :)
1
1
(W.r.t. variants I think fully-qualified is definitely better for a serious codebase, but for gists like this it's just noise. Either that or I'm too used to Haskell atm.)
1
Show replies

