
25 Jul
2012
25 Jul
'12
5:02 p.m.
Hi, I always write functions like this: addPlayer :: PlayerInfo -> State Game Bool addPlayer pi@(PlayerInfo {playerNumber = pn}) = do pls <- gets players case find (\(PlayerInfo {playerNumber = myPn}) -> pn == myPn) pls of Nothing -> do modify (\game -> game { players = pi : pls}) return True otherwise -> return False It simply adds a new PlayerInfo to a list contained in Game, with the condition that it doesn't exists already. Do you see a more elegant way to do this? Best, Corentin