possible bug

Jonathon Bell jbell@mathsoft.com
Wed, 18 Apr 2001 14:19:59 -0400


Hello there,

I've been experimenting with the use of type dependencies in type classes
and have come across something i find surprising. Could it in fact be a bug
in the implementation? I'm using Hugs Feb 2001, with switches +o and -98:

>  class Bug f a r | f a -> r where
>
>     bug::f->a->r
>
>  instance                   Bug (Int->r)  Int      r
>--instance ...
>  instance (Bug f a r)    => Bug f        (c a)    (c r) 
>
>  f:: Bug(Int->Int) a r => a->r
>  f = bug(id::Int->Int)

The above compiles fine and at the prompt ..

Main> f (f [0::Int])

...runs with an expected program error that member 'bug' has not been
defined. Fine. But

Main> f (f (f [0::Int]))

-- ...fails to compile with an unresolved overloading:

*** ERROR - Unresolved overloading
*** Type       : (Bug (Int->Int) Int a, Bug(Int->Int) a v => [b]
*** Expression : f (f (f [0]))

which is a surprise. it appears as though the compiler is failing to exploit
the dependency '|f a->r'
from which it could infer that 'a' in the above message must in fact be
'Int', etc...

Many thanks for investigating this...

________________________________
Jonathon Bell jbell@mathsoft.com
MathSoft, Inc.  www.mathsoft.com
101 Main St, Cambridge, MA 02142
(617) 577-1017 x745