<br><br><div class="gmail_quote">On Fri, Aug 3, 2012 at 11:34 PM, Matthew <span dir="ltr">&lt;<a href="mailto:wonderzombie@gmail.com" target="_blank">wonderzombie@gmail.com</a>&gt;</span> wrote:<br><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></blockquote><div><br></div><div>The short answer is to write a &quot;one liner&quot; using (&gt;&gt;=) and (&gt;&gt;), unless you need to bind more than one value to a variable.  In that case, you should use an applicative interface, if available and otherwise possible, and finally do-notation.</div>
</div>