# stack overflow in tail recursive function

5 messages
Open this post in threaded view
|

## stack overflow in tail recursive function

 Hi all, I have this tail recursive factorial function: factorial :: Integer -> Integer factorial 0 = 1 factorial n = fat' n 1 where     fat' 1 fat = fat     fat' n fat = fat' (n-1) (n*fat) Whenever I run it with a number of 20000 or more I get a stack overflow error. It doesn't seem a problem with the large resulting number because, if so, the message should be something like "Garbage collection fails to reclaim sufficient space". Other functions seem to able to handle a larger number of recursive calls. So, what is the problem with this particular function? -- Bruno Schneider http://www.dcc.ufla.br/~bruno/_______________________________________________ Hugs-Users mailing list [hidden email] http://www.haskell.org/mailman/listinfo/hugs-users
Open this post in threaded view
|

## Re: stack overflow in tail recursive function

 Hi Bruno, I suggest you ask this question on the haskell-cafe@ mailing list - it's a general Haskell question, and you'll get a much more detailed answer there. Thanks, Neil On Tue, Mar 23, 2010 at 12:01 PM, Bruno Schneider <[hidden email]> wrote: > Hi all, > > I have this tail recursive factorial function: > > factorial :: Integer -> Integer > factorial 0 = 1 > factorial n = fat' n 1 where >    fat' 1 fat = fat >    fat' n fat = fat' (n-1) (n*fat) > > Whenever I run it with a number of 20000 or more I get a stack > overflow error. It doesn't seem a problem with the large resulting > number because, if so, the message should be something like "Garbage > collection fails to reclaim sufficient space". Other functions seem to > able to handle a larger number of recursive calls. > > So, what is the problem with this particular function? > > -- > Bruno Schneider > http://www.dcc.ufla.br/~bruno/> _______________________________________________ > Hugs-Users mailing list > [hidden email] > http://www.haskell.org/mailman/listinfo/hugs-users> _______________________________________________ Hugs-Users mailing list [hidden email] http://www.haskell.org/mailman/listinfo/hugs-users
Open this post in threaded view
|