4 ms·
> You can do this with any functor. Not to be pedantic, but being a functor has little to do with the fact that you can add and remove elements from lists. Kn
by tmhedberg 14y ago
> You can do this with any functor.
Not to be pedantic, but being a functor has little to do with the fact that you can add and remove elements from lists.
Knowing that a particular type is an instance of `Functor` tells you only one thing about that type: that you can `fmap` functions over its contents. But look at `fmap`'s type:
fmap :: Functor f => (a -> b) -> f a -> f b
There is no function with that type which can extract values from a functor, nor insert new ones. `fmap` can only modify the values already contained by the functor, leaving them in the container.
Extraction of contained values from a wrapper and lifting/insertion of values into a wrapper require pattern matching and constructor application respectively, which means the type must have exposed constructors, a property independent of whether that type is a functor.