[Haskell-cafe] Flip around type parameters?

Christopher Howard christopher.howard at frigidcode.com
Fri May 10 05:39:12 CEST 2013


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 555 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130509/117de252/attachment.pgp>


More information about the Haskell-Cafe mailing list