Thanks Brent and David, that's very neat! <br>I always forget to use these operators 'on', 'when', 'any'...<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"><<a href="mailto:byorgey@seas.upenn.edu" target="_blank">byorgey@seas.upenn.edu</a>></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>
><br>
<br>
This is a little better, it avoids all the record syntax for<br>
extracting player numbers, and uses 'any' instead of 'find' since we<br>
don't actually care about the player with the given number if they<br>
exist:<br>
<div><br>
> addPlayer :: PlayerInfo -> State Game Bool<br>
</div>> addPlayer pi = do<br>
> pls <- gets players<br>
> let exists = any (((==) `on` playerNumber) pi) pls<br>
> when (not exists) $ modify (\game -> game { players = pi : pls})<br>
> 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>