[Haskell-cafe] pragma to request tail recursion optimization (and perhaps [co]inductive recursion)

Petr P petr.mvd at gmail.com
Thu Oct 25 21:14:39 CEST 2012


Haskell compilers optimize tail recursive functions as cycles, which
improves both memory and CPU complexity. However, it's easy to make a
mistake and break the conditions under which a function can be tail
recursive and thus optimized. Is there a way to tell a Haskell
compiler that a function must be tail recursive and if it cannot be
done, fail the compilation? Like Scala's @tailrec? I'd say no, and
believe it would be quite handy. I suppose this could be realized as a

There could be also additional pragmas to ensure that a recursive
function is inductive (the recursive call is on a strict sub-structure
of one of the arguments) or co-inductive (the recursive call is
guarded by a constructor).

  Best regards,
  Petr Pudlak

More information about the Haskell-Cafe mailing list