Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm guessing you're using <code>monads-fd</code>.</p> <pre><code>$ ghci t.hs -hide-package mtl *Main Data.List&gt; testMyDiv1 1 0 "*** Exception: My divison by zero *Main Data.List&gt; :i Either ... instance Monad (Either e) -- Defined in Control.Monad.Trans.Error ... </code></pre> <p>Looking in the <a href="http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-Trans-Error.html" rel="nofollow">transformers</a> package, which is where <code>monads-fd</code> gets the instance, we see:</p> <pre><code>instance Monad (Either e) where return = Right Left l &gt;&gt;= _ = Left l Right r &gt;&gt;= k = k r </code></pre> <p>So, no definition for Fail what-so-ever. In general, <code>fail</code> is discouraged as it isn't always guaranteed to fail cleanly in a monad (many people would like to see <code>fail</code> removed from the Monad class).</p> <p>EDIT: I should add that it certainly isn't clear <code>fail</code> was intentioned to be left as the default <code>error</code> call. A ping to haskell-cafe or the maintainer might be worth while.</p> <p>EDIT2: The <code>mtl</code> instance has been <a href="http://hackage.haskell.org/trac/ghc/ticket/4159#comment:1" rel="nofollow">moved to base</a>, this move includes removing the definition of <code>fail = Left</code> and discussion as to why that decision was made. Presumably, they want people to use ErrorT more when monads fail, thus reserving <code>fail</code> for something more catastrophic situations like bad pattern matches (ex: <code>Just x &lt;- e</code> where <code>e --&gt;* m Nothing</code>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload