haskell - Is GHC able to tail-call optimize IO actions? -
Will the GHC optimize tail-mail on the following functions by default? The only strange thing about it is that it defines an IO action repeater, but I do not know why it can not be TCO'd.
import control. Concurrent Consumption of MVR:: MVR A -> [A] - & gt; Io (Consumption _ [] = Return () Consumption Shop (X: X) = MARM Store Store X Store X
Since your code
store (x: xs) = putMvar store & gt; & Gt; Store X is not actually called in tail position, but if you run ghc -O and turn on Optimizer, then The -dump-simplified option will show you the output of the intermediate code of GHC, and it is actually a tail-recursive function, which will be compiled in a loop.
So the answer is that GHC will not optimize it by default; You need the -O option.
(Experiment with GHC version 6.10.1).
Comments
Post a Comment