[Haskell-cafe] Trouble with types
Yitzchak Gale
gale at sefer.org
Tue Dec 25 03:27:12 EST 2007
Hi Konstantin,
Here is yet another possible approach:
Perhaps you really meant what you wrote in your definition
of firstFunction - namely, that it needs to be polymorphic,
so that it can convert to _any_ type that is an instance
of SecondClass.
In that case, you might want to add another method to
SecondClass:
class SecondClass a where
secondConstructor :: Double -> a
secondFunction :: a -> Double
instance SecondClass SecondData where
secondConstructor = SecondData
secondFunction (SecondData d) = d
Now you can say:
instance FirstClass FirstData where
firstFunction (FirstData d) = secondConstructor d
In short, it all depends on what exactly you are trying
to do.
Hope this helps,
Yitz
More information about the Haskell-Cafe
mailing list