[Haskell-cafe] Fwd: Is there any way to parametrize a value update using record syntax?

Poprádi Árpád popradi_arpad at freemail.hu
Wed Sep 7 20:16:49 CEST 2011


Hi David,

thank You for your suggestions but the usage of fclabes is much better
for me (otherwise it uses template haskell inside too).

Some benefits:
- It has a nice example for usage.
- Not even a little wrapper is needed to make a get (or set) with a
record field. You can use the field name directly for both direction
(get and set).
- It's prepared for usage in a state monad.
- A record field is represented with a value (and a type) so you can
easily compose it (one of the main problem with haskell's original
record field syntax).

Thanks,
Árpád
 
On Tue, 2011-09-06 at 14:55 -0700, David Barbour wrote:
> forgot to CC list. 
> 
> ---------- Forwarded message ----------
> From: David Barbour <dmbarbour at gmail.com>
> Date: 2011/9/6
> Subject: Re: [Haskell-cafe] Is there any way to parametrize a value
> update using record syntax?
> To: Poprádi Árpád <popradi_arpad at freemail.hu>
> 
> 
> 2011/9/6 Poprádi Árpád <popradi_arpad at freemail.hu>
>         But it's ugly. Always the same, only the record selector has
>         another
>         name. Is it possible to generalize it?
> 
> 
> You can generalize using template haskell. I believe Oleg's HList
> already provides such mechanisms, so you don't need to do this
> yourself. If you're doing this a lot, try the HList package. (If not,
> just do the 
> 
> 
> Also, I would say you've too tightly coupled your BigData to the
> MonadicEnv. I suggest you reduce it instead to:
> 
> 
>   setX :: X -> BigData -> BigData
>   setX x' bd = bd { dataX = x' }
> 
> 
>   updX :: (X -> X) -> BigData -> BigData
>   updX fx bd = bd { dataX = fx (dataX bd) }
> 
> 
> Then in your state monad you can use:
>   modify (setX x')
>   gets dataX
> 
> 
> And use of 'updX' is much more composable. 
> 
> 
> That aside, from personal experience, I'm usually okay just using:
>   modify (\ s -> s { dataX = x' })
> 
> 
> in the few places I need it. 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> 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