<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, May 4, 2014 at 3:39 PM, Mathijs Kwik <span dir="ltr"><<a href="mailto:mathijs@bluescreen303.nl" target="_blank">mathijs@bluescreen303.nl</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="">
</div>An expression that demands itself isn't necessarily an infinite loop<br>
either. So this still boils down to the halting problem.<br>
<br>
a :: [Int]<br>
a = [length a * 2, length a * 3, length a * 4]<br></blockquote><div><br>To be more precise, I believe we're looking to catch an expression where
 evaluating it to head-normal form demands itself already evaluated in 
head-normal form.  In your example, there is no loop because `length a` 
can be evaluated without evaluating any of the items in `a`.  But you 
get an infinite loop if you make cons strict in the item:<br><br>    {-# LANGUAGE BangPatterns #-}<br>    import Prelude hiding (length)<br><br>    -- | List whose cons is strict in the value.<br>    data SList a = Nil | Cons !a (SList a)<br>

        deriving Show<br><br>    infixr 5 `Cons`<br><br>    length :: SList a -> Int<br>    length xs0 = go 0 xs0<br>      where<br>        go !n Nil = n<br>        go !n (Cons _ xs) = go (n+1) xs<br><br>    a :: SList Int<br>

    a = (length a * 2) `Cons` (length a * 3) `Cons` (length a * 4) `Cons` Nil<br><br>    main :: IO ()<br>    main = print a<br><br></div></div></div></div>