29 Jul 1999 16:58:53 GMT, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> pisze:
> Is it possible to set up classes that express the following (using
> ghc extensions)?
[...]
I hoped that the following would work (with -fglasgow-exts
-fallow-overlapping-instances -fallow-undecidable-instances)
but it does not choose the instance of SubsetOfPoint I want.
Question still open.
class Shape a where
subset :: Shape b => b -> a -> Bool
{- Does not matter yet.
data AnyShape = forall a. Shape a => AnyShape a
instance Shape AnyShape where
x `subset` AnyShape y = x `subset` y
-}
data Point = Point Double Double deriving Eq -- The first shape.
instance Shape Point where
subset = subsetOfPoint
class SubsetOfPoint a where
subsetOfPoint :: a -> Point -> Bool
instance Shape a => SubsetOfPoint a where
subsetOfPoint _ _ = False -- Generic version if the specialized one is
-- not defined. But this is always chosen...
instance SubsetOfPoint Point where
subsetOfPoint = (==)
main = do
print (Point 1 1 `subset` Point 1 1) -- Prints False.
--
__("< Marcin Kowalczyk * [EMAIL PROTECTED] http://kki.net.pl/qrczak/
\__/ GCS/M d- s+:-- a22 C+++>+++$ UL++>++++$ P+++ L++>++++$ E-
^^ W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP->+ t
QRCZAK 5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-