Sorry about bad title. I have a problematic data type, which I'm trying to define as instance of functor.
So basically, what I have is something, which has
sample_logp :: s a -> a
and it should be transformed using
(a -> b)
to
sample_logp :: s b -> b
. The following code does not quite accomplish this, and succeeds only in
sample_logp :: s a -> b
.
data Model s a = Model {
sample_logp :: s a -> a
}
instance Functor (Model s) where
fmap f m = Model {
sample_logp = sample_logp'
} where sample_logp' x = (f . (sample_logp m)) x
Is what I'm trying even possible? If so, how could this code be updated to achieve this?
ais at both covariant and contravariant position. - zakyggapssis. - zakyggapssto be aContravariant, you can define a functor instance forModel s. It's hard to tell whether that would be useful for your case. - chiInvariantinstance for it, but that may not win you much. - dfeuer