Q:

Haskell circular definition interrupt

Hello everyone i came over a curious thing trying to learn circular definition in Haskell. We have these two cases:
module Main
where    
  mgood = 1:head (tail (tail mgood)):mgood

  list = take 10 mgood

  main = do

       print list

For the code above i get this output [1,1,1,1,1,1,1,1,1,1] which i understand why but the proble is in this code:
module Main
where
  mbad = 1:head (tail (tail (tail mbad))):mbad

  list = take 10 mbad

  main = do

       print list

Where i get this output [1, {Interrupted!}. Can someone explain me why this happens and what's the difference between the 2 cases?

A:

Both of your definitions fit the pattern result = foo : bar : result. So what we end up with, in both cases, is a circular list that looks like this:
foo : bar : foo : bar : foo : bar : ...

In both cases foo is 1, so it doesn't depend on anything else. But bar does.
In mgood you define bar to be equal to the third element of the list, so bar is equal to foo, which is 1. So both foo and bar are 1 and that's what you get: an infinite list of 1s.
In mbad you define bar to be equal to the fourth element. So bar is equal to itself. This infinitely recursive definition of bar leads to an infinite loop when trying to evaluate bar.

