[Haskell-cafe] Flip around type parameters?

kudah kudahkukarek at gmail.com
Fri May 10 06:03:10 CEST 2013


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)
> --------
> 
> 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.
> 



More information about the Haskell-Cafe mailing list