<p>The do notation in this instance yields a nice advantage: if you want to switch to a different monad to encapsulate failure you will meely need to swap out the type signature and your function will need no further work.</p>

<div class="gmail_quote">On Aug 4, 2012 7:35 AM, &quot;Matthew&quot; &lt;<a href="mailto:wonderzombie@gmail.com">wonderzombie@gmail.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I&#39;m a somewhat experienced coder but I am relatively new to Haskell.<br>
I&#39;ve got a question about whether a usage of do notation is idiomatic,<br>
or whether it&#39;s better to use pattern matching.<br>
<br>
I&#39;ve got two functions which take an input and return Maybe SomeType.<br>
If either returns Nothing, I also want to return Nothing. If they both<br>
return something, then I&#39;ll return something unrelated.<br>
<br>
With do notation, I can write something like this:<br>
<br>
        do<br>
          foo &lt;- callFoo x<br>
          bar &lt;- callBar x<br>
          return (baz)<br>
<br>
Alternatively, there&#39;s a straightforward pattern match. After binding<br>
foo, bar in a couple of where clauses:<br>
<br>
        case (foo,bar) of (Just x, Just y) -&gt; baz<br>
                          _                -&gt; Nothing<br>
<br>
So which approach is more idiomatic, do you think?<br>
<br>
Thanks,<br>
- Matthew<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div>