Method contexts
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Sun Jan 28 14:22:09 EST 2001
Sun, 28 Jan 2001 19:41:15 +0100, Hannah Schroeter <uk1o at rz.uni-karlsruhe.de> pisze:
> Why can't you write:
>
> class Eq k => Member c k where
> member :: c -> k -> Bool
>
> > class Member c a => Seq c a
>
> instance Eq a => Member [a] a where
> ...
>
> > instance Seq [a] a
Because the last instance is then illegal: requires Eq a in the
context, which I obviously don't want.
BTW, there is a bug in the ghc's CVS HEAD. The following program:
class Eq k => Member c k where
member :: c -> k -> Bool
class Member c a => Seq c a where
list :: c -> [a]
instance Eq a => Member [a] a where
member = flip elem
instance Seq [a] a where
list = id
type F = Int -> Int
test:: [F] -> F -> Bool
test = member
main:: IO ()
main = print ((id :: F) == id)
does compile. When the definition of test is removed, there is a
correst error about missing instance Eq (Int -> Int). The use of
member:: [F] -> F -> Bool magically creates this instance!
Unfortunately it does not really allow to compare functions and the
answer is <<loop>> :-)
--
__("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTÊPCZA
QRCZAK
More information about the Glasgow-haskell-bugs
mailing list