[Haskell] GHC / Hugs Disagree on Constraints
Dominic Steinitz
dominic.steinitz at blueyonder.co.uk
Tue Oct 5 13:37:21 EDT 2004
oleg at pobox.com wrote:
>>instance (Ord a, Bits a, Bounded a, Integral a, LargeWord a,
>> Bits b, Bounded b, Integral b, LargeWord b) =>
>> Bounded (LargeKey a b) where
>> minBound = 0
>> maxBound =
>> fromIntegral $
>> (1 + fromIntegral (maxBound::b))*
>> (1 + fromIntegral (maxBound::a)) - 1
>>
>>Hugs rejects it with +N -98 with
>
>
> One fix is to bring type variables into the local scope, for
> example,
>
>
>>instance (Ord a, Bits a, Bounded a, Integral a, LargeWord a,
>> Bits b, Bounded b, Integral b, LargeWord b) =>
>> Bounded (LargeKey a b) where
>> minBound = 0
>> maxBound :: (LargeKey a b) =
>> fromIntegral $
>> (1 + fromIntegral (maxBound::b))*
>> (1 + fromIntegral (maxBound::a)) - 1
>
>
> You still need -98 flag for Hugs. Another solution is totally
> Haskell98: introduce two functions
>
>
>>aoflk:: (LargeKey a b) -> a; aoflk = undefined
>>boflk:: (LargeKey a b) -> b; boflk = undefined
>
>
> then maxBound can be implemented as
>
>
>> maxBound = result where
>> result =
>> fromIntegral $
>> (1 + fromIntegral (maxBound `asTypeOf` (boflk result)))*
>> (1 + fromIntegral (maxBound `asTypeOf` (aoflk result))) - 1
>
>
> The apparent recursion in the above definition is superficial. The
> definition isn't actually recursive. We merely need the type of the
> 'result' rather than its value.
>
>
>
Oleg,
Thanks for this. It seems strange that the scope of the universal
quantifier is the function definition (in your first solution) rather
than the whole of the instance.
Is asTypeOf really Haskell 98?
Dominic.
More information about the Haskell
mailing list