hmemcpy / milewski-ctfp-pdf

Bartosz Milewski's 'Category Theory for Programmers' unofficial PDF and LaTeX source
https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/
Other
10.88k stars 578 forks source link

An error (?) in the jigsaw puzzle at page 121 #229

Closed jfet97 closed 4 years ago

jfet97 commented 4 years ago

Not sure about that, maybe I've misunderstood something but...

This is the BiComp Bifunctor presented at page 120

newtype BiComp bf fu gu a b = BiComp (bf (fu a) (gu b))

instance (Bifunctor bf, Functor fu, Functor gu) => Bifunctor (BiComp bf fu gu) where 
  bimap f1 f2 (BiComp x) = BiComp ((bimap (fmap f1) (fmap f2)) x)

So f1 and f2 are "normal" functions that are mapped firstly by the Functors fu and gu respectively, then are mapped together by the Bifunctor bf. As expected, f1 and f2 are presented in this way at page 121:

f1 :: a -> a'
f2 :: b -> b'

Therefore, the expected signature for the bimap function of the BiComp Bifunctor shouldn't be: (a -> a') -> (b -> b') -> bf (fu a) (gu b) -> bf (fu a') (gu b')? Corresponding to the given definition of bimap that is: f1 -> f2 -> BiComp x -> ...

I'm asking because it is presented differently at page 121: (fu a -> fu a') -> (fu b -> fu b') -> bf (fu a) (gu b) -> bf (fu a') (gu b')

BartoszMilewski commented 4 years ago

It's a different bimap. The first one is for BiComp bf fu gu the last one is for bf. These different implementations are not marked by the name fo the bifuncor, because GHC figures that out. Maybe a subscript bimap_{bf} would help?

jfet97 commented 4 years ago

Uh, I've completely misunderstood the sentence "The outer bimap breaks through the outer bf layer", most likely because English is not my mother tongue. Anyway shame on me because I should have thought that you weren't talking about the Bicomp's bimap. Now taking a closer look, I see that it's the bf's bimap type signature šŸ˜…

Obviously, in my case, a subscript bimap_{bf} would have been very helpful, but honestly, I'm in no position to suggest anything šŸ˜…šŸ˜…šŸ˜