title: Relation between the Semigroupoid and Semigroup classes
body: <p>In the last week I've been trying to grasp some of Haskell's "core" types and type classes (but have been studying Haskell for at most two weeks total), and I've found something that bugs me:</p>
  
  <ul>
  <li>a "Semigroupoid" is a generalization of a "Category", meaning that any Category is trivially a Semigroupoid, just by ignoring it's own identity and defining </li>
  </ul>
  
  <p><code>o = (.)</code></p>
  
  <ul>
  <li>also a "Semigroup" is a generalization of a "Monoid", in the exact same connotation as above: one just has to ignore mempty and define</li>
  </ul>
  
  <p><code>(&lt;&gt;) = mappend</code></p>
  
  <p>These two facts alone, and the idea that both Semigroupoids and Semigroups only have a notion of combining elements (semigroupoid-composition vs semigroup-multiplication) and both Category and Monoid also have a notion of "unity" (identity vs unit element) bring to mind that one could express relations between Semigroupoids and Semigroups, and between Categories and Monoids as follows</p>
  
  <pre><code>import Prelude hiding (id, (.))
  
  import Data.Semigroupoid
  import Data.Semigroup
  
  import Control.Category
  import Data.Monoid
  
  instance Semigroupoid c =&gt; Semigroup (c a a) where
      (&lt;&gt;) = o
  
  instance Category c =&gt; Monoid (c a a) where
      mempty = id
      mappend = (.)
  
  main = putStrLn "Does not type-check!"
  </code></pre>
  
  <p>Now, I'm not sure why this doesn't compile; the ghc compiler says:</p>
  
  <pre><code>All instance types must be of the form (T a1 ... an)
  where a1 ... an are *distinct type variables*,
  and each type variable appears at most once in the instance head.
  </code></pre>
  
  <p>but it happens that including</p>
  
  <p><code>{-# LANGUAGE FlexibleInstances #-}</code></p>
  
  <p>on top of the file fixes everything.</p>
  
  <p>The relations expressed above don't seem to be built in the libraries, while the relations between Semigroupoid and Category, and between Semigroup and Monoid are be built in.</p>
  
  <p>Is there any specific reason for this, and I'm just missing it?</p>
  
  <p>Maybe it has something to do with the mysterious "FlexibleInstances"?</p>
  
  <p>Any insight would be greatly appreciated.</p>