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

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -