3 ms·
Thanks, jerf! This is really good stuff. One question on functor: Does the thing returned have to be "the same shape" as the original? That is, if I have a
by AnimalMuppet 5y ago
Thanks, jerf! This is really good stuff.
One question on functor: Does the thing returned have to be "the same shape" as the original? That is, if I have a list, and I fmap on it, do I always get a list back? Or am I only guaranteed to get some kind of functor back? If I am guaranteed to get a list back, am I guaranteed that it has the same number of elements?
To use your initial language, is it fair to say that a functor takes a source of a, and a function that converts a to b, and returns a source of b of the same "shape" as the original source of a?
If it's true, that makes the function example clearer to me. Of course it has to return a function, because the shape of the input was "function".
(And, did the article answer this and I just missed it?)
- yakshaving_jgt 5y agoThe answer to your first question is yes. You can see that in the types. fmap :: (a -> b) -> f a -> f b The `a` becomes a `b` (which could be a different type but not necessarily), but the `f` is the same `f`.