fno-implicit-prelude and literal numeric patterns
Bernard James POPE
bjpop@cs.mu.OZ.AU
Sat, 20 Jul 2002 16:30:47 +1000 (EST)
Hi all,
I wrote:
> I know I'm becoming a pest with this, but another question about
> -fno-implicit-prelude:
>
> What happens with literal numeric patterns?
Ok the various bits and pieces that I think are relevent:
The Haskell Language Report:
3.17.3 Formal Semantics of Pattern Matching
(h) case v of { k -> e; _ -> e' } = if (v==k) then e else e'
where k is a numeric, character, or string literal.
(s) case v of { x+k -> e; _ -> e' }
= if v >= k then (\x -> e) (v-k) else e'
where k is a numeric literal
Rule (h) in Figure 4 involves the overloaded operator ==;
it is this rule that d efines the meaning of pattern matching
against overloaded constants.
The Ghc users guide:
7.5.4. Rebindable syntax
In an n+k pattern, the standard Prelude Ord class is still
used for comparison, but the necessary subtraction uses
whatever "(-)" is in scope (not "Prelude.(-)").
The user's guide is silent about which version of Eq is used
for literal patterns, but I assume that it follows the (n+k)
example and so Prelude Eq is used for the overloaded use
of ==.
What is the reason for using Prelude.Ord (and Prelude.Eq)?
This seems very limiting since you can replace Num but you can't
replace Eq, and moreover, your new versions of the Numeric classes
must be subclasses of Prelude.Eq, rather than another Eq.
Is there are strong reason for avoiding the alternative:
"whatever == and >= are in scope"? Perhaps it is the if-then-else
that must refer to Prelude.Bool?
Cheers,
Bernie.