[Haskell-beginners] Very little (golfing) question...
Corentin Dupont
corentin.dupont at gmail.com
Thu Jul 26 11:23:36 CEST 2012
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 <byorgey at seas.upenn.edu>wrote:
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120726/261f5cbe/attachment.htm>
More information about the Beginners
mailing list