Type resolution problem

Juan Carlos Arevalo Baeza jcab@roningames.com
Mon, 28 May 2001 17:53:38 -0700


    I'm having a little of a problem with a project of mine. Just check out 
this, which is the minimum piece of code that will show this problem:

----
type MyType a = a

(+++) :: MyType a -> MyType a -> MyType a
a +++ b = a

class MyClass a where
     baseVal :: a

val1 :: MyClass a => MyType a
val1 = baseVal

val2 :: MyClass a => MyType a
val2 = baseVal

-- combVal :: MyClass a => MyType a
combVal = val1 +++ val2      -- line 18 is here...
----

    Trying this in Hugs returns the following error:

----
ERROR E:\JCAB\Haskell\testcv.hs:18 - Unresolved top-level overloading
*** Binding             : combVal
*** Outstanding context : MyClass b
----

    Now, how can it possibly say that the context "MyClass b" is 
outstanding? What does this mean?

    Uncommenting the type expression above clears the error. But, why can't 
the compiler deduce it by itself? I mean, if a function has type shaped 
like in (a -> a -> a) and it is used with parameters (cv => a) where the 
constrains are identical, then the result MUST be (cv => a) too, right? Or 
am I missing something here?

    Don't get me wrong, I can just put type declarations everywhere in my 
code. It's a good thing, too. But this problem is really nagging at me 
because I don't get where the problem is.

    Any ideas or pointers?

    Salutaciones,
                               JCAB

---------------------------------------------------------------------
Juan Carlos "JCAB" Arevalo Baeza    | http://www.roningames.com
Senior Technology programmer        | mailto:jcab@roningames.com
Ronin Entertainment                 | ICQ: 10913692
                        (my opinions are only mine)
JCAB's Rumblings: http://www.metro.net/jcab/Rumblings/html/index.html