4 ms·
FWIW, Const q a = Const q fmap _ (Const q) = Const q is a perfectly viable Functor on a. Good luck converting a a into one of those.
by a1369209993 7y ago
FWIW,
Const q a = Const q
fmap _ (Const q) = Const q
is a perfectly viable Functor on a. Good luck converting a a into one of those.
- crimsonalucard 7y agoI wrote something to refute your example, but then I realized that you're right.
- tel 7y agoWhat's hard about that? C and D are Hask. F_Q maps objects A to objects Const Q A, and fmap takes functions in Hom(a, b) to Hom(Const Q a, Const Q b). We identify that Const Q a is just a little subset of Hask, so Hom(Const Q a, Const Q b) is Hom(Q, Q) and fmap works by mapping all functions to id_Q. Now fmapId and fmapComp are satisfied trivially.
- kmill 7y agoa1369209993 was answering my "I don't think [natural transformations from the identity functor] always exist" with "no, they don't." The natural transformation would be a function "a -> Const q a" for all a. There can't be a way to do this for all q that is somehow natural in q, since this would have to construct a value of q to put into the Const constructor. Worse, (even though vanilla Haskell doesn't allow it), q might be the empty type, so there might be no functions "a -> Const q a" whatsoever. I think the point of the example is that keeping q polymorphic is a simulation of the empty type. Allowing empty types, I'm happy with the example. However, this is technically a natural transformation in Haskell: f :: a -> Const q a f x = Const undefined x since every type contains bottom (undefined).
- tel 7y agoAh, I misunderstood! And yes, absolutely. An even easier example data Nullity a This is a perfectly valid functor, too. Ignoring undefined, there are no values of it, but fmap cannot be used to create values of the mapped type, just manipulate them.