-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 7/2/10 07:23 , Vincent Hanquez wrote: > I'm not sure exactly what the API would looks like, but I think basically you > would enter/leave the state monad quite frequently in incremental mode, > since the whole point of the incremental api is having this context built > partially. for this reason, you end up with something really close to explicit > state keeping, isn't it ?
You can do this if you need to (execState) but it's better to wrap the whole thing in a State monad. Think of it this way: (flip runState) can be read as "withContext": > flip runState initContext $ do > -- do stuff, invoking update as needed to build the state Although now that I think about it, if we're just appending to the state, this should possibly be a Writer instead of a State; the interface is simpler. Or to try to be a little more concrete about it: > type HashContext = String > > -- build up a hash context incrementally, then hash it > hashWithContext :: () -> Hash > hashWithContext = hash . execWriter > > -- add a chunk to the hash context > addToHash :: String -> Writer HashContext () > addToHash = tell > -- use it > messageHash = hashWithContext $ do > -- do something > addToHash aLine > -- doSomethingElse > foldM addToHash [aListOfStuff] > -- ... - -- brandon s. allbery [linux,solaris,freebsd,perl] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkwt/z0ACgkQIn7hlCsL25Uz5wCeO9db+eqE/azqoEgJ3L3vQJzF XKEAn0I8rEzf0tQfylc3pGq4+E6V4M72 =C/BN -----END PGP SIGNATURE----- _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe