>
>Let's make this more concrete and fill out those definitions... and also
>include the important class definition from p.32. The definitions are a
>bit contrived to get the types right:
>
>| class Foo a where foo :: a -> a
>| class Foo a => Bar a where bar :: a -> a
>|
>
>| instance Num a => Foo [a] where
>| foo [] = []
>| foo (x:xs) = map (x+) xs
>|
>
>| instance (Eq a, Text a) => Bar [a] where
>| bar [] = []
>| bar (x:xs) = foo xs where u = x==x
>| v = show x
>|
>
>
>Now suppose that you wanted to evaluate bar "abcde". This would require that
>you also have instances:
> o Eq Char and Text Char (from the second instance declaration). Neither
> of these is a problem.
> o Foo [Char]. Well this isn't a problem at first because there is a
> matching instance declaration. But that declaration also requires that
> there is an instance Num Char. No such instance exists!
>So, when you try this in Gofer, you get:
>
>| ? bar "abcde"
>| ERROR: Cannot derive instance in expression
>| *** Expression : bar d133 "abcde"
>| *** Required instance : Bar [Char]
>| *** No subdictionary : Num Char
>
>The part of the report that you refer to is intended to describe the static
>checks that will be performed in a proper Haskell system to detect this error
>at an earlier stage. (Remember, Gofer is not a proper Haskell system.) On
>the other hand, the Gofer approach has its advantages. For example, in Gofer
>we can evaluate:
>
>| ? bar [1..4]
>| [5, 6]
>
>The fact that the existence of instances Eq a and Text a does not in general
>imply the existence of an instance Num a does not matter here because, when
>a is replaced by the type Int of integers, all three instances are defined.
Ok. Agreed. Actually I had considered this point before posting.
But consider this example
class Foo a => Bar a where ...
instance (Eq a, Text a) => Foo [a] where ...
instance Num a => Bar [a] where ....
data X a = X a
which Haskell says is valid. Complete the above program as Mark
has done above.Now for the expression
bar [(X 1),(X 2)]
the Haskell compiler has to give the message that there is no
instance Bar [X int]. This is similar to the above message
for the expression (bar "abcde"). What I argue is that I will
give a similar message for the first program also.There is no need to
make the first program illegal. You are also denying some
valid programs as Mark has given above.
[EMAIL PROTECTED]