[Haskell-cafe] is there a more concise way to generate helper functions for a datatype built on records?

Neil Mitchell ndmitchell at gmail.com
Sat Nov 24 11:23:51 EST 2007


Hi

Some of these can be automatically derived by the Data.Derive tool. If
you want any more, then submit a patch and they can all be derived.

http://www-users.cs.york.ac.uk/~ndm/derive/

The derivations Set, Is, From, Has, LazySet all look useful. A bit
more documentation on what each one does would also be handy, if
anyone wants to write it!

Thanks

Neil

On Nov 24, 2007 4:01 PM, Thomas Hartman <tphyahoo at gmail.com> wrote:
> I think I'm running into more or less the same issue discussed at
>
> http://bloggablea.wordpress.com/2007/04/24/haskell-records-considered-grungy/
>
> Just wondering if I missed anything, or if any of the ideas
> considering better records setter/getters have been implemented in the
> meantime.
>
> t.
>
>
> **************
>
> -- Is there any way to do the following more concisely?
> -- Seems like a lot of boilerplate
>
> data GameState = GameState { guesses :: Int, userHighScores ::
> UserHighScores, answer :: Maybe Int }
>   deriving Show
>
> -- State Helpers ---------------------------------------
> modGuesses f gSt  = _set_guesses ( (f . guesses) gSt) gSt
> modUserHighScores f gSt = _set_userHighScores ( (f . userHighScores) gSt) gSt
> modAnswer f gSt = _set_answer ( (f . answer) gSt) gSt
>
> _set_guesses new gSt   = gSt {guesses=new}
> _set_userHighScores new gSt = gSt { userHighScores=new }
> _set_answer new gSt = gSt { answer=new }
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list