Christopher Howard | 10 May 05:39 2013

Flip around type parameters?

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
--------
(Continue reading)

kudah | 10 May 06:03 2013
Picon

Re: Flip around type parameters?

No. You'll have to use a newtype. Type parameter order is a huge deal
for some types, e.g. monad transformers, you'd better think about it
beforehand.

On Thu, 09 May 2013 19:39:12 -0800 Christopher Howard
<christopher.howard <at> frigidcode.com> wrote:

> 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)
> --------
> 
(Continue reading)


Gmane