Compiler Development: Rust or OCaml?
BRANK

Before presenting my actual argument, I will show two analogous implementations of CPS conversion for a very simple language, without making any conclusions. The general approach is borrowed from “Compiling with Continuations” by Andrew W. Appel. No worries if you are not familiar with the idea; the only thing to focus your attention on is how the idea is implemented in both Rust and OCaml.Here is CPS conversion written in Rust:use std::cell::RefCell; use std::ops::Deref; use std::rc::Rc; // A variable identifier of the lambda language `Term`. type Var = String; // The lambda language; direct style. type Term = Rc<TermTree>; enum TermTree { Var(Var), Fix(Vec<(Var, Vec<Var>, Term)>, Term), Appl(Term, Vec<Term>), Record(Vec<Term>), Select(Term, u32), } use TermTree::*; #[derive(Clone)] enum CpsVar { // Taken from the lambda term during CPS conversion. CLamVar(Var), // Generated uniquely during CPS conversion. CGenVar(u32), } use CpsVar::*; // The re…

hirrolot.github.io
Related Topics: OCaml Rust