Haskell endless loop with just repetitive action
I have code like this:
let n = [1,2,3,4] n [1,2,3,4] 0:n [0,1,2,3,4] let n = 0:n
And when I type the Haskell interpreter after the top level:
I am getting infinite result:
And where the seal "0" is endless.
Why am I getting this result?
Is there some kind of recursive stuff and why / how does it work at the interpreter level?
Can I catch a stack overflow, what's on GHCi or not?
is similar to
other languages like ML: bindings are allowed to be recursive. In other words, it
n = 0:n
as a list, where the first element
is and the rest of the list is equal
. This means the second element
is equal to the first element
, which is
In Haskell, because of laziness, infinite lists are fine. If you only use the first 10 elements of the list, then the 11th element and subsequent ones will never be evaluated.
source to share