Hi. Does Haskell allow you to flip around type parameters somehow? I was playing around with toy code (still learning the fundamentals) and I came up with a class like this:
code:
--------
class Rotatable2D a where
rotate :: (Num b) => (a b) -> b -> (a b)
--------
It was easy to make an instance of a generic single-parameter type:
code:
--------
data Angle a = Angle a
deriving (Show)
instance Rotatable2D Angle where
rotate (Angle a) b = Angle (a + b)
--------
But let's say I have something a little more complicated:
code:
--------
data CircAppr a b = CircAppr a a b -- radius, rotation angle, number of
points
--------
I think I need something like so:
--------
instance Rotatable2D (\x -> CircAppr x a) where
rotate (CircAppr a b c) d = CircAppr a (b + d) c
--------
But I tried that and it isn't valid syntax.
--
frigidcode.com
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
