title: Functional Dependencies / Type Families
body: <p>With functional dependencies I can constrain type of dependent parameter in a type class using multi-parameter type classes. Just like this:</p>
  
  <pre><code>{-# LANGUAGE FunctionalDependencies, MultiParamTypeClasses,TypeSynonymInstances  #-}
  
  class (Num a, Integral b) =&gt; F a b | a -&gt; b where
    f :: a -&gt; b
  
  instance F Int Int where
    f = id
  
  instance F Float Integer where
    f = truncate
  </code></pre>
  
  <p>And everything'll work perfectly.</p>
  
  <pre><code>&gt; f (1 :: Int)
  1
  &gt; f (1.9 :: Float)
  1
  </code></pre>
  
  <p>But if I try to write something like</p>
  
  <pre><code>instance F Double String where
    f = show
  </code></pre>
  
  <p>I'll get the following compilation error:</p>
  
  <pre><code>No instance for (Integral String)
  arising from the superclasses of an instance declaration
  Possible fix: add an instance declaration for (Integral String)
  In the instance declaration for `F Double String'
  </code></pre>
  
  <p>Is there a way to approach this with type families instead of fundeps?</p>