In message <[EMAIL PROTECTED]>, Byron
Cook writes:
> Because Haskell.org is down I cannot read what the report says about this
> case, but logic tells me that hug's typechecker is mishandling @ patterns
>
> this function typechecks:
> ----------------------------------------------------------------------
> replace :: (Register r, Register r') => RAT s r (VirtualReg r r') ->
> Cell r ->
> ST s (Cell (VirtualReg r r'))
>
> replace r (Reg r x) = .........
> replace r (PC x) = return $ PC x
> ----------------------------------------------------------------------
>
> but this one does not:
> ----------------------------------------------------------------------
> replace :: (Register r, Register r') => RAT s r (VirtualReg r r') ->
> Cell r ->
> ST s (Cell (VirtualReg r r'))
> replace r (Reg r x) = .........
> replace r y@(PC x) = return y
> ----------------------------------------------------------------------
>
> Cell is a polymorphic datatype that is not polymorphic in the PC
> constructor:
>
> data Cell r = Reg r Int
> | PC Int
> .
> .
> .
> .
I guess the hugs' treatment of @ is correct at least w.r.t. your program.
Since the argument of the data constructor, PC, is of type Int, the
expressioln ``PC x'' can be of type `` Cell r'' for any r. For a simpler
example, please consider the Maybe type:
data Maybe a = Just a | Nothing
In this case, the following function is correct:
f :: Maybe Int -> Maybe String
f (Just x) = Just (show x)
f Nothing = Nothing
However, the following is incorrect:
f :: Maybe Int -> Maybe String
f (Just x) = Just (show x)
f y@Nothing = y
The type checking environment includes y::Maybe Int (after unfication),
implying that the result of the second equation of f should be of type
Maybe Int. This incurs the same typing error as the one you met.
-----
Yoshihiko Ichikawa, Dept of Info Sci, Fac of Sci, Ochanomizu University
Phone: +81-3-5978-5708 (Dial-in) / +81-3-5978-5704 (Library of Department)
Fax: +81-3-5978-5898 (Faculty) / +81-3-5878-5705 (Library of Department)
E-mail: [EMAIL PROTECTED]