Bug? Or at least a better error message?

Brian Hulley brianh at metamilk.com
Mon Jun 5 10:44:02 EDT 2006


Simon Peyton-Jones wrote:
> Right.  The crash was definitely a bug, but it seems to have been
> fixed.
>
>
> The error message about ambiguity is just what you'd expect.

I must admit I can't understand where the ambiguity actually is.
bar has been defined as a -> Int, so surely anything on the rhs of an 
equation for an instance of the bar method in Foo is therefore an Int also, 
so having to explicitly write 1::Int seems superfluous.

       bar([x]) = 1    -- why is ::Int needed when we know that bar:: a->Int 
???

Also, the error message suggests that the ambiguity is caused by Foo t and 
Num t, but what's the problem - surely this just means t belongs to both Foo 
and Num?

Thanks, Brian.

>
> So it seems that this is all fine.
>
> Simon
>
>> -----Original Message-----
>> From: glasgow-haskell-users-bounces at haskell.org
>> [mailto:glasgow-haskell-users- bounces at haskell.org] On Behalf Of
>> Geoffrey Alan Washburn
>> Sent: 04 June 2006 18:53
>> To: glasgow-haskell-users at haskell.org
>> Cc: Stephanie C Weirich
>> Subject: Re: Bug? Or at least a better error message?
>>
>>
>> I just upgraded to ghc  6.5.20060603 and now I get the following
>> error
>>
>>    Prelude> :load strange.hs
>>    [1 of 1] Compiling Testing          ( strange.hs, interpreted )
>>
>>    strange.hs:9:13:
>>        Ambiguous type variable `t' in the constraints:
>>          `Foo t' arising from use of `bar' at strange.hs:9:13-19
>>          `Num t' arising from the literal `1' at strange.hs:9:18
>>        Probable fix: add a type signature that fixes these type
>>        variable(s)
>>    Failed, modules loaded: none.
>>
>> If I wrap "1" with ( :: Int) it seems to be accepted.
>>
>>
>> Geoffrey Alan Washburn wrote:
>>> While trying out the following example, in an attempt to learn
>>> something about the fiddly case where a type class instance tries
>>> to use an instance that is more specific than itself
>>>
>>>   module Testing where
>>>
>>>   class Foo a where { bar :: a -> Int }
>>>
>>>   instance Foo Int where
>>>     bar i = i
>>>
>>>   instance Foo a => Foo [a] where
>>>     bar [] = bar [1]
>>>     bar ([x]) = 1
>>>     bar (x:xs) = (bar x) + (bar xs)
>>>

-- 
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com 



More information about the Glasgow-haskell-users mailing list