I run into trouble trying to make Vector.Generic.Vector an instance of other typeclasses (in my case - Functor).
I could settle for adding a Functor instance to Vector.Unboxed.Vector, but I couldn't figure out the syntax for that either. My best take was to try something like:
instance (U.Unbox a, U.Unbox b) => Functor U.Vector where
fmap = U.map
But the compiler (justfully) complained that 'a' and 'b' where nowhere after '=>'. Can I even make this definition for Functor, as it assumes more restrictions on the types fmap is allowed to take?
Most stuff I found in SO was too advanced for me to figure out, so please be gentle :-)
Think of the type of fmap
:
fmap :: Functor f => (a -> b) -> f a -> f b
You are trying to add the constraint that a
and b
are both instances of Unbox
. This is not doable because fmap
is completely general while a map of an unboxed Vector
is specific to instances Unbox
.
It cannot be made a Functor
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With