Algebraic Structures: Things I wish someone had explained about FP
This post shows a Haskell-ish definition of Functor, then attempts to show the same thing in TypeScript.<p><pre><code>    interface Functor&lt;A&gt; {
        map&lt;B&gt;(f: (a: A) =&gt; B): Functor&lt;B&gt;;
    }
</code></pre>
But the TypeScript definition loses something important: the point of a Functor is that you get back the <i>same</i> data type -- there&#x27;s one `f` in the Haskell defn both in the argument and return type, while this TS definition can give you back any random data type.  E.g. the implementation of Array.map could give you back an Either.<p>I don&#x27;t mean this comment to be a random nitpick of the post.  Trying to think these things through is hard, and trying to use things you know to help understand the new idea is not unreasonable.  But in particular with PL each thing has so much associated baggage (here in TS, subtyping) that reasoning &quot;by metaphor&quot; often means you end up missing the critical point.