[Haskell-cafe] GHC bug? Let with guards loops

Dan Doel dan.doel at gmail.com
Tue Jul 9 17:05:17 CEST 2013


The definition

    Just x | x > 0 = Just 1

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:

    Just x | x > 0  = Just 1
           | x <= 0 = Just 0

What is x?


On Tue, Jul 9, 2013 at 10:42 AM, Andreas Abel <andreas.abel at ifi.lmu.de>wrote:

> Hi, is this a known bug or feature of GHC (7.4.1, 7.6.3)?:
>
> 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:
>
>   works = case Just 1 of { Just x | x > 0 -> x }
>
>   loops = let Just x | x > 0 = Just 1 in x
>
> works returns 1, loops loops.  If x is unused on the rhs, the
> non-termination disappears.
>
>   works' = let Just x | x > 0 = Just 1 in 42
>
> 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...
>
> Cheers,
> Andreas
>
> --
> Andreas Abel  <><      Du bist der geliebte Mensch.
>
> Theoretical Computer Science, University of Munich
> Oettingenstr. 67, D-80538 Munich, GERMANY
>
> andreas.abel at ifi.lmu.de
> http://www2.tcs.ifi.lmu.de/~**abel/ <http://www2.tcs.ifi.lmu.de/~abel/>
>
> ______________________________**_________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/**mailman/listinfo/haskell-cafe<http://www.haskell.org/mailman/listinfo/haskell-cafe>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130709/f20f3729/attachment.htm>


More information about the Haskell-Cafe mailing list