I have a type Image
which is basically an c-array of floats. It is easy to create functions
such as map :: (Float -> Float) -> Image -> Image
, or zipWith :: (Float -> Float -> Float) -> Image -> Image -> Image
.
However, I have a feeling that it would also be possible to provide something that looks like an applicative instance on top of these functions, allowing more flexible pixel level manipulations like ((+) <$> image1 <*> image2)
or ((\x y z -> (x+y)/z) <$> i1 <*> i2 <*> i3)
. However, the naive approach fails, since Image type cannot contain things other than floats, making it impossible to implement fmap
as such.
How could this be implemented?