> data X a b = X a b> instance Functor (X a) where
> fmap f (X a b) = X a (f b)
Yeah, that works just fine.
On Fri, Jul 17, 2009 at 1:14 PM, Petr Pudlak wrote:
> Hi, I have probably a very simple question, but I wasn't able to figure it
> out
> myself.
>
> Consider a two-parameter data type
Petr,
Short answer: you can't. Easiest way to workaround is to define a
newtype wrapper around your original datatype:
newtype X' b a = X' {unX' :: X a b}
instance Functor (X' b) where
fmap g (X' (X a b)) = X' (X b (g a))
Err
fmap g (X' (X a b)) = X' (X (g a) b)
Cheers,
Stefan
Petr,
If I want to make it a functor in the last type variable (b), I can
just define
instance Functor (X a) where
fmap f (X a b) = X a (f b)
But how do I write it if I want X to be a functor in its first type
variable?
Short answer: you can't. Easiest way to workaround is to define a
Hi, I have probably a very simple question, but I wasn't able to figure it out
myself.
Consider a two-parameter data type:
> data X a b = X a b
If I want to make it a functor in the last type variable (b), I can just define
> instance Functor (X a) where
> fmap f (X a b) = X a (f b)
But how