[Haskell-cafe] foldl and space problems
Gracjan Polak
gracjan at acchsh.com
Mon Jun 13 09:29:21 EDT 2005
Bernard Pope wrote:
> Perhaps you could post the definition of the state type? Or even better,
> a small example of code that runs badly.
I still don't know where old code had problems, but after rewriting
everything it seems to run smoothly now :) Thanks for all ideas, btw.
I "invented" something like this:
type RestAndState = (MyState -> [MyData]) -> MyState -> [MyData]
this is the type of funtions that take current state and continuation as
parameters. Example:
putValues v1 v2 v3 rest state =
[v1,v2,v3] ++ rest state
there is a bit of syntactic ugliness when state chages:
putValueEx v1 rest state =
let newstate = state { ... } in
[v1] ++ rest nstate
good thing is that function can be composed quite easily with ($):
putV v1 v2 v3 v4 rest = -- state skipped here :)
putValue v1 v2 v3 $
putValueEx v4 rest
It works as I want it to. But I have strange feeling that there must be
a better way to "compose" foldr and state... Does anybody have any idea
how to put monad into this?
--
Gracjan
More information about the Haskell-Cafe
mailing list