<div dir="ltr">Many also use the Control.Applicative syntax for this sort of thing (most types that have a Monad instance also have an Applicative instance):<div><br></div><div>(,) &lt;$&gt; ma &lt;*&gt; mb</div><div><br></div>
<div>which is equivalent to:</div><div><br></div><div>do</div><div>  a &lt;- ma</div><div>  b &lt;- mb</div><div>  return (a, b)</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Sep 6, 2013 at 2:04 PM, Emmanuel Touzery <span dir="ltr">&lt;<a href="mailto:etouzery@gmail.com" target="_blank">etouzery@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"><div dir="ltr"><div><div><div><div>Hmm I&#39;ve been looking some more. Turns out I&#39;m pretty sure... What I&#39;ve been looking for is liftMx.<br>
<br></div>In this case, liftM2.<br><br></div>liftM2 ... doA doB<br><br></div>
where &quot;...&quot; represents the rest of the computation as it did in the example snippet I sent in my first email.<br><br></div>In the case of the Maybe monad, &quot;...&quot; will be called with the &quot;Just&quot; values and only if both doA and doB are not Nothing.<br>

<br>and for &quot;n&quot; operations, there is &quot;ap&quot;, I&#39;ll look at that one too.<span class="HOEnZb"><font color="#888888"><br><br>emmanuel<br></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">On Fri, Sep 6, 2013 at 10:43 PM, Emmanuel Touzery <span dir="ltr">&lt;<a href="mailto:etouzery@gmail.com" target="_blank">etouzery@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"><p>Thank you (and the others) for tips. I&#39;ll check the suggestions but yes sequence requires that all items have the same type so that sequence2 would work better but feels un-idiomatic.<br>


I needed such code several times in several contexts, so i assumed the answer would be obvious. Maybe i&#39;m structuring my code the wrong way for haskell, i&#39;ll rethink those functions. Thanks for now!</p><span><font color="#888888">
<p>Emmanuel</p></font></span><div><div>
<div class="gmail_quote">On Sep 6, 2013 10:37 PM, &quot;Nicholas Vanderweit&quot; &lt;<a href="mailto:nick.vanderweit@gmail.com" target="_blank">nick.vanderweit@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">


<div dir="ltr">It seems like he wants something like sequence, but for tuples. Say:<div><br></div><div>sequence2 :: Monad m =&gt; (m a, m b) -&gt; m (a, b)</div><div>sequence2 (ma, mb) = ma &gt;&gt;= \a -&gt; mb &gt;&gt;= \b -&gt; return (a, b)</div>



<div><br></div><div>But without knowing the use case it&#39;s hard to know whether or not this could be done simply with &quot;sequence&quot; and mapM*</div><div><br></div><div><br></div><div>Nick</div></div><div class="gmail_extra">



<br><br><div class="gmail_quote">On Fri, Sep 6, 2013 at 2:28 PM, Michael Steele <span dir="ltr">&lt;<a href="mailto:mikesteele81@gmail.com" target="_blank">mikesteele81@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">



The `sequence`, `mapM`, and `mapM_` functions may be what you are looking for.<br>
<br>
let allTogether = sequence [doA, doB, doC, doZ]<br>
<div>case allTogether of<br>
  Nothing -&gt; ...<br>
</div>  Just as -&gt; ...<br>
<br>
<br>
Use `maybe` and `fromMaybe` to avoid case statements:<br>
<br>
fromMaybe &quot;failure!&quot; $ do<br>
    as &lt;- sequence [doA, doB, doC, doZ]<br>
    return $ &quot;Success: &quot; ++ show (length as)<br>
<br>
The `catMaybes` function can be used to execute each computation in<br>
the list even if some of them return nothing.<br>
<div><div><br>
On Fri, Sep 6, 2013 at 12:49 PM, Emmanuel Touzery &lt;<a href="mailto:etouzery@gmail.com" target="_blank">etouzery@gmail.com</a>&gt; wrote:<br>
&gt; Hello,<br>
&gt;<br>
&gt;  I&#39;m often using the Maybe monad to combine Maybe computations one after the<br>
&gt; other without conditionals.<br>
&gt;<br>
&gt;  But I&#39;m not sure how to do it, when I have several operations which return<br>
&gt; Maybe and I want all the indiviual values in the end, not a combination of<br>
&gt; the values.<br>
&gt;<br>
&gt;  Currently I do:<br>
&gt;<br>
&gt; let allTogether = do<br>
&gt;   ma &lt;- doA<br>
&gt;   mb &lt;- doB<br>
&gt;   return (ma, mb)<br>
&gt; case allTogether of<br>
&gt;   Nothing -&gt; ...<br>
&gt;   Just (a, b) -&gt; ...<br>
&gt;<br>
&gt;  This way in this case I have one case instead of two, however I&#39;m sure<br>
&gt; there must be a nicer way to achieve this result?<br>
&gt;<br>
&gt;  Thank you!<br>
&gt;<br>
&gt; Emmanuel<br>
&gt;<br>
</div></div><div>&gt; _______________________________________________<br>
&gt; Beginners mailing list<br>
&gt; <a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
&gt;<br>
<br>
<br>
<br>
</div><span><font color="#888888">--<br>
-- Michael Steele<br>
</font></span><div><div><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>