title: Haskell - Maybe arithmetic
body: <p>I have been asked to implement a function which uses the following profile:</p>
  
  <pre><code>maybe_divide :: Maybe Integer -&gt; Maybe Integer -&gt; Maybe Integer
  </code></pre>
  
  <p>and responds in the following manner:</p>
  
  <pre><code>&gt; maybe_divide (Just 5) (Just 2) 
  Just 2
  &gt; maybe_divide (Just (-5)) (Just 2) 
  Just (-3)
  &gt; maybe_divide (Just (-5)) (Just 0) 
  Nothing
  &gt; maybe_divide Nothing (Just 1) 
  Nothing
  &gt; maybe_divide (Just 1) Nothing
  Nothing
  </code></pre>
  
  <p>I have written the following but it will not compile. Do you guys have any suggestions?</p>
  
  <pre><code>maybe_divide :: Maybe Integer -&gt; Maybe Integer -&gt; Maybe Integer
  maybe_divide x y = case x of
      Just x' -&gt; case y of 
          Just y'
              | y' == 0 -&gt; Nothing  
              | otherwise -&gt; x' `div` y'
      Nothing -&gt; Nothing 
  </code></pre>