title: "Inheriting" operations in haskell data types
body: <p>I have created the following type:</p>
  <pre class="lang-hs prettyprint-override"><code>data Inch = Inch Double
  instance Show Inch where
      show (Inch i) = show i ++ &quot; inches&quot;
  </code></pre>
  <p>Now, I'd like to be able to perform some mathematical operations on this type and, since the type itself is basically just a synonym with <code>Double</code> I was expecting to get them for free. However, this is not the case:</p>
  <pre class="lang-hs prettyprint-override"><code>ghci&gt; (3 :: Double) / 2
  1.5
  ghci&gt; (3 :: Inch) / 2
  
  &lt;interactive&gt;:74:2: error:
      • No instance for (Num Inch) arising from the literal ‘3’
      • In the first argument of ‘(/)’, namely ‘(3 :: Inch)’
        In the expression: (3 :: Inch) / 2
        In an equation for ‘it’: it = (3 :: Inch) / 2
  
  &lt;interactive&gt;:74:13: error:
      • No instance for (Fractional Inch) arising from a use of ‘/’
      • In the expression: (3 :: Inch) / 2
        In an equation for ‘it’: it = (3 :: Inch) / 2
  </code></pre>
  <p>I think I can solve this by defining:</p>
  <pre class="lang-hs prettyprint-override"><code>(/) :: Inch -&gt; Double -&gt; Inch
  (Inch i) / n = Inch (i GHC.Real./ n)
  </code></pre>
  <p>This allows the previous code to run fine:</p>
  <pre class="lang-hs prettyprint-override"><code>ghci&gt; (Inch 3) / 2
  1.5 inches
  </code></pre>
  <p>But I feel it's cumbersome and can't help thinking there surely must be a better way.
  Is there?</p>