
Thanks Brent and David, that's very neat!
I always forget to use these operators 'on', 'when', 'any'...
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...
On Thu, Jul 26, 2012 at 2:31 AM, Brent Yorgey
On Wed, Jul 25, 2012 at 11:02:39PM +0200, Corentin Dupont wrote:
This is a little better, it avoids all the record syntax for extracting player numbers, and uses 'any' instead of 'find' since we don't actually care about the player with the given number if they exist:
addPlayer :: PlayerInfo -> State Game Bool addPlayer pi = do pls <- gets players let exists = any (((==) `on` playerNumber) pi) pls when (not exists) $ modify (\game -> game { players = pi : pls}) return $ not exists
-Brent
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners