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

Reply via email to