[Haskell-cafe] Haskell Data Structure design

amindfv at gmail.com amindfv at gmail.com
Sat Jul 9 02:55:17 UTC 2016


>> On Fri, Jul 8, 2016 at 9:57 PM, Guru Devanla <gurudev.devanla at gmail.com> wrote:


>> 1.  I see that almost in every function I deal with state, I have e <- get , expression in the begining. I always ending up having to use the state to query for different values. I guess this is OK.


> El 8 jul 2016, a las 22:07, William Yager <will.yager at gmail.com> escribió:
> 
> For #1, look into using the Lens library's support for the State monad. You can often avoid doing a get, and instead write things like `fees += 5`, which will add 5 to the field in the state called "fees".
> 

Lens is a pretty heavy extra thing for a beginner to have to learn -- you'll do fine with the 'modify' function:

modify :: (s -> s) -> State s ()

So instead of writing:

do
   s <- get
   put (s + 5)

You say:

modify (+5)


Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160708/37a39ef7/attachment.html>


More information about the Haskell-Cafe mailing list