[Haskell-beginners] recursive and non recursive functions

Dan Lior sitiposit at gmail.com
Wed Sep 18 08:41:54 CEST 2013


The following snippet is from a recent stack overflow post (by someone else). 



7
down vote
accept
I'd like to mention an important distinction:

cyclic' = [0,1] ++ cyclic'

cyclic'' = [0,1] ++ x
    where x = cyclic''
These two functions are recursive. But

cyclic = let x = 0 : y 
             y = 1 : x
         in x
is not! It uses x internally, which is recursive, but the whole cyclic isn't. This is also why they're different when compiled into the core language.

This has some important practical implications, namely that recursive functions can't be inlined, but non-recursive can. 

Presumably, 

cyclic = let 
		x = [0,1] ++ y
		y = x
	       in x

is another "nonrecursive function".

I don't understand the distinction. I imagine that it is related to the let…in clause, but I don't think that I understand that either. Can someone try to clarify this ?

dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130918/bf187951/attachment.htm>


More information about the Beginners mailing list