问题
Specifically referring to https://bartoszmilewski.com/2015/04/07/natural-transformations/
Author says "This is not a functor".
I can define fmap :: (a -> b) -> (a -> a) -> (b -> b)
as fmap f aa = id
, which seems to adhere to the functor laws.
I don't mean why it's not explicitly part of the Functor typeclass in X language, I just mean why it wouldn't be acknowledged as a functor.
回答1:
In the context of Haskell, I think you're talking about newtype Endo a = Endo (a -> a)
(using a newtype to get the required * -> *
kind).
Indeed we could define
instance Functor Endo where
fmap _ _ = Endo id
But one of the Functor laws is fmap id = id
, i.e. fmapping with id has to be the same as doing nothing. Your suggested definition violates this rule:
fmap id (Endo toUpper)
should result in Endo toUpper
, but your code makes it Endo id
. One of those transforms 'a'
to 'A'
, the other turns 'a'
into 'a'
.
来源:https://stackoverflow.com/questions/48853854/why-is-a-a-not-a-functor