[clean-list] Parametrizing instance declarations
David C. Norris
David_Norris at brown.edu
Tue Sep 25 00:25:01 MEST 2007
How might one define the following three class instances without
duplicating code? My attempts to parametrize the declaration fail with
errors such as
(1) type variable of type of lifted argument b appear in the specified type
(2) internal overloading of "_createArray" could not be solved.
----------------------------------------------
class copyElt e :: {#e} Int -> e
instance copyElt Char
where
copyElt a i = c.[0]
where
c :: {#Char}
c = {a.[i]}
instance copyElt Int
where
copyElt a i = c.[0]
where
c :: {#Int}
c = {a.[i]}
instance copyElt Real
where
copyElt a i = c.[0]
where
c :: {#Real}
c = {a.[i]}
----------------------------------------------
What I would hope to accomplish is something like:
instance copyElt e | e <- [Char, Int, Real] // bogus syntax
where
copyElt a i = c.[0]
where
c :: {#e}
c = {a.[i]}
Regards,
David
More information about the clean-list
mailing list