What are bifunctors?
<p>I'm relatively new to Haskell and having trouble understanding the utility of bifunctors. I think I understand them in theory: say for example if I wanted to map across a type that abstracts multiple concrete types, such as Either or Maybe, I'd need to encapsulate them in a bifunctor. But on the one hand, those examples seems particularly contrived, and on the other it does seem like you could achieve that same functionality simply through composition. </p>

<p>As an example, I came across this code in <a href="https://www.cs.ox.ac.uk/jeremy.gibbons/publications/iterator.pdf" rel="noreferrer"><em>The Essence of the Iterator Pattern</em></a> by Jeremy Gibbons and Bruno C. d. S. Oliveira:</p>

<pre><code>import Data.Bifunctor

data Fix s a = In {out::s a (Fix s a) }

map' :: Bifunctor s =&gt; (a -&gt; b) -&gt; Fix s a -&gt; Fix s b
map' f = In . bimap f (map' f) . out

fold' :: Bifunctor s =&gt; (s a b -&gt; b) -&gt; Fix s a -&gt; b
fold' f = f . bimap id (fold' f) . out

unfold' :: Bifunctor s =&gt; (b -&gt; s a b) -&gt; b -&gt; Fix s a
unfold' f = In . bimap id (unfold' f) . f
</code></pre>

<p>I understand the point is to compose mapping and folding functions to create an iterator pattern and this is achieved by defining a data constructor that requires two parameters. But in practice I don't understand how this is any different then using a regular functor and composing the functions with fmap instead of bimap. I think I clearly must be missing something, both with this example and, likely, in general.</p>