<div dir="ltr">The definition<br><div><br> Just x | x > 0 = Just 1<br><br></div><div>is recursive. It conditionally defines Just x as Just 1 when x > 0 (and as bottom otherwise). So it must know the result before it can test the guard, but it cannot know the result until the guard is tested. Consider an augmented definition:<br>
<br></div><div> Just x | x > 0 = Just 1<br></div><div> | x <= 0 = Just 0<br><br></div><div>What is x?</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 9, 2013 at 10:42 AM, Andreas Abel <span dir="ltr"><<a href="mailto:andreas.abel@ifi.lmu.de" target="_blank">andreas.abel@ifi.lmu.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, is this a known bug or feature of GHC (7.4.1, 7.6.3)?:<br>
<br>
I got a looping behavior in one of my programs and could not explain why. When I rewrote an irrefutable let with guards to use a case instead, the loop disappeared. Cut-down:<br>
<br>
works = case Just 1 of { Just x | x > 0 -> x }<br>
<br>
loops = let Just x | x > 0 = Just 1 in x<br>
<br>
works returns 1, loops loops. If x is unused on the rhs, the non-termination disappears.<br>
<br>
works' = let Just x | x > 0 = Just 1 in 42<br>
<br>
Is this intended by the Haskell semantics or is this a bug? I would have assumed that non-recursive let and single-branch case are interchangeable, but apparently, not...<br>
<br>
Cheers,<br>
Andreas<br>
<br>
-- <br>
Andreas Abel <>< Du bist der geliebte Mensch.<br>
<br>
Theoretical Computer Science, University of Munich<br>
Oettingenstr. 67, D-80538 Munich, GERMANY<br>
<br>
<a href="mailto:andreas.abel@ifi.lmu.de" target="_blank">andreas.abel@ifi.lmu.de</a><br>
<a href="http://www2.tcs.ifi.lmu.de/~abel/" target="_blank">http://www2.tcs.ifi.lmu.de/~<u></u>abel/</a><br>
<br>
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>