corollary icon indicating copy to clipboard operation
corollary copied to clipboard

Output is built up quadratically

Open pshc opened this issue 8 years ago • 2 comments

One thing that I do feel strongly about: building up output by interpolating Strings recursively is expensive.

I'd want rip that bandaid off ASAP, but also avoid making things overly complex. What do you think? Some suggestions:

  • tool PrintState appropriately
  • fn print_expr(PrintState, &ast::Expr) -> OutExpr where OutExpr: Display

I would tend toward the latter, but I don't know what shape of output structures we might want yet.

EDIT: tooling PrintState appropriately also means we could do indentation semi-automatically

pshc avatar May 12 '17 22:05 pshc

Sorry for not responding to this earlier, but now I think is the right time since we have most of the Haskell AST represented and the start of most Rust equivalents. Gradually converting from the top down or bottom up is fine with me.

Would this be similar to generating a Rust AST, in effect? Does one exist that isn't overly complex? We don't need the full expressiveness of the Rust AST though so a handmade solution should work too.

(And I'll be thrilled when indentation isn't so clumsy.)

tcr avatar May 22 '17 17:05 tcr

I agree, one approach would be to start with a string wrapper and slowly add enum cases as usecases come up, maybe like

mod ir {
    enum Expr {
        Free(String),
        Parens(Box<Expr>),
    }
}

(usecase for Parens might be collapsing nested parens)

Also maybe a custom trait or macro for output (so we can skip std::fmt's error handling)...?

pshc avatar May 23 '17 03:05 pshc