[Haskell-cafe] use of modules to save typing

Nils ml at n-sch.de
Thu Jul 8 19:48:43 EDT 2010


On 08.07.2010 11:15, Michael Mossey wrote:
> Whoa, I just realized I'm not using 'modify' to full advantage. This can
> be written
>
> incrCursor = modify incrCursor'
> incrCursor' (PlayState cursor len verts doc) =
> PlayState (min (cursor+1)(len - 1)) len verts doc)

Thats what lambdas are good for:

incrCursor = modify $ \p@(PlayState c l _ _) -> p { cursor = min (c+1) 
(l-1) }

Or...

incrCursor = modify $ \p at PlayState { cursor = c, len = l } -> p { cursor 
= min (c+1) (l-1) }

:)


More information about the Haskell-Cafe mailing list