Thanks Brent and David, that&#39;s very neat! <br>I always forget to use these operators &#39;on&#39;, &#39;when&#39;, &#39;any&#39;...<br>I also always hesitate on the container to use, list, sets or something else... Now everything is done with lists since they are very well supported by the prelude...<br>
<br><div class="gmail_quote">On Thu, Jul 26, 2012 at 2:31 AM, Brent Yorgey <span dir="ltr">&lt;<a href="mailto:byorgey@seas.upenn.edu" target="_blank">byorgey@seas.upenn.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Jul 25, 2012 at 11:02:39PM +0200, Corentin Dupont wrote:<br>
&gt;<br>
<br>
This is a little better, it avoids all the record syntax for<br>
extracting player numbers, and uses &#39;any&#39; instead of &#39;find&#39; since we<br>
don&#39;t actually care about the player with the given number if they<br>
exist:<br>
<div><br>
&gt; addPlayer :: PlayerInfo -&gt; State Game Bool<br>
</div>&gt; addPlayer pi = do<br>
&gt;     pls &lt;- gets players<br>
&gt;     let exists = any (((==) `on` playerNumber) pi) pls<br>
&gt;     when (not exists) $ modify (\game -&gt; game { players = pi : pls})<br>
&gt;     return $ not exists<br>
<span><font color="#888888"><br>
-Brent<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>