Type Classes and the StdEnv
Ron Wichers Schreur
ronny@cs.kun.nl
Thu, 27 Nov 1997 19:44:54 +0100
Nick Kallen wrote (to the Clean discussion list):
> I see the error:
>
> Type error [a.icl,7,Start]: "Start" cannot be overloaded: [...]
>
> But I haven't the slightest clue why this arises. What is going
> wrong?
Perhaps the following example will make this clear:
module t
class f a :: a
instance f Int where f = 1
instance f Real where f = 1.0
Start = f
The typechecker cannot resolve the overloading here, should it
use the instance of f for Int or Real? The programmer has to
specify a type for Start in this case, for example:
Start :: Int
Start = f
A related error message results from the following program:
module t
import StdEnv
Start = toReal (fromReal 1.1)
This will give the error message
"fromReal" (internal) overloading is insolvable
In this case the typechecker cannot resolve the overloading
because there are several types possible for the intermediate
result (fromReal 1.1). Again the solution is to provide more
type information. One possibility:
Start = toReal value
where
value :: Int
value = fromReal 1.1
Overloading is described in section 8.4 of the Clean reference
manual.
Cheers,
Ronny Wichers Schreur