title: Haskell type error with catch
body: <p>I am playing with some online examples, and one has this phrase:</p>
  
  <pre><code>   do ... contents &lt;- getDirectoryContents path `catch` const (return []) 
  </code></pre>
  
  <p>But it won't compile for me, and gives the error:</p>
  
  <pre><code>No instance for (Exception e0) arising from a use of `catch'
  The type variable `e0' is ambiguous
  Possible fix: add a type signature that fixes these type variable(s)
  Note: there are several potential instances:
    instance Exception NestedAtomically
      -- Defined in `Control.Exception.Base'
    instance Exception NoMethodError
      -- Defined in `Control.Exception.Base'
    instance Exception NonTermination
      -- Defined in `Control.Exception.Base'
    ...plus 7 others
  In a stmt of a 'do' block:
    contents &lt;- getDirectoryContents path `catch` const (return [])
  In the expression:
    do { contents &lt;- getDirectoryContents path
                     `catch` const (return []);
  </code></pre>
  
  <p>I had to change it to give a type for the handler, which is OK now but a bit messier:</p>
  
  <pre><code>contents &lt;- getDirectoryContents path `catch` (\(SomeException e) -&gt; const (return []) e)
  </code></pre>
  
  <p>So I am wondering why I needed to make this change, and if this is the most concise way to do it.
  (Yes, I know I could use alternate forms of try, handle, ...)</p>