Problem with 'nested' pattern matching

RijkJ.C.vanHaaften RijkJ.C.vanHaaften
Fri, 01 Feb 2002 12:12:37 +0100


--=====================_25737288==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

carlos wrote:
>Hello.
>
>         I'm having some trouble trying to understand exactly what's 
> behind the rule for pattern-matching with data constructors. The code I'm 
> having trouble with is similar to this:
>
>f (C p1 p2 (C2 p3 p4)) = ...
>f _ = False
>
>What happens is if f is called with (C p1 p2 (NOT_C2 ...)), I get a 
>program error, and not False.

I tried this in Hugs:

data Test
     = C  Bool Bool Test
     | C2 Bool Bool
     | NOT_C2 Int

f :: Test -> Bool
f (C p1 p2 (C2 p3 p4)) = (p1 && p3) || (p2 && p4)
f _ = False

evaluating f (C True False (NOT_C2 25)) gives False as expected.
Which compiler/interpreter do you use? Which version?

Actually I can't imagine a bug of this kind in any of the mainstream 
compilers (GHC, HBC, NHC and NHC) and interpreters (Hugs, GHCi, and HBI), 
though on this computer I only can check hugs.

Regards,

Rijk-Jan van Haaften

--=====================_25737288==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
carlos wrote:<br>
<blockquote type=cite cite><font color="#010101">Hello. <br>
<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>I'm having
some trouble trying to understand exactly what's behind the rule for
pattern-matching with data constructors. The code I'm having trouble with
is similar to this: <br>
<br>
f (C p1 p2 (C2 p3 p4)) = ... <br>
f _ = False <br>
<br>
What happens is if f is called with (C p1 p2 (NOT_C2 ...)), I get a
program error, and not False.</font></blockquote><br>
I tried this in Hugs:<br>
<br>
data Test<br>
&nbsp;&nbsp;&nbsp; = C&nbsp; Bool Bool Test<br>
&nbsp;&nbsp;&nbsp; | C2 Bool Bool<br>
&nbsp;&nbsp;&nbsp; | NOT_C2 Int<br>
<br>
f :: Test -&gt; Bool<br>
f (C p1 p2 (C2 p3 p4)) = (p1 &amp;&amp; p3) || (p2 &amp;&amp; p4)<br>
f _ = False <br>
<br>
evaluating f (C True False (NOT_C2 25)) gives False as expected.<br>
Which compiler/interpreter do you use? Which version?<br>
<br>
Actually I can't imagine a bug of this kind in any of the mainstream
compilers (GHC, HBC, NHC and NHC) and interpreters (Hugs, GHCi, and HBI),
though on this computer I only can check hugs.<br>
<br>
Regards,<br>
<br>
Rijk-Jan van Haaften<br>
</html>

--=====================_25737288==_.ALT--