[Haskell-cafe] Question on optimization

Todd Wilson twilson at csufresno.edu
Tue Dec 15 22:05:13 UTC 2020


Dear Cafe,

In code of the form
    case as ++ bs of
      [] -> ...
      x:xs -> ...
under what circumstances is the overhead of cons-cell creation for the
elements of `as` that would happen in an eager language avoided?
Always? Is the answer the same if `f` is defined by simple list
recursion and we call `f (as ++ bs)`? What if `f` is defined in a
different module (or comes from the Prelude)?

I know that questions of this type can be answered in specific cases
by looking at the (intermediate) code generated by the compiler, but
more generally, are there some succinct principles that everyday
programmers can hang on their cubicle walls that summarize a lot of
what they can expect from the compiler in terms of optimizations?

Todd Wilson


More information about the Haskell-Cafe mailing list