
25 Jul
2012
25 Jul
'12
8:31 p.m.
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