[Haskell] a newbie question

Ben_Yu at asc.aon.com Ben_Yu at asc.aon.com
Fri Apr 23 22:21:03 EDT 2004





Hi there.

I got this question while I'm messing around with my toy monad.

I was thinking about creating a generic monad that can persist state change
even when fail is called. The StateT monad will discard the state change so
it makes it hard to add tracing to the program. (at least to me. If there's
any nice way of doing this, please kindly instruct me.)

Then I come to this problem. I can summarize it by removing all irrelavant
stuff like this:

to_write :: ((x->a)->r) -> (x->(a,s)) -> (r,s)
to_write f1 f2 = ...

how do I implement it?

I can't get a data of type x, so the only way is to pass f2 into f1. In
order to pass f2 to f1, I have to discard the s returned by f2. Thus, I
lose the s forever.

Hope I'm getter myself clear.

Any comment is welcome.


Ben.



More information about the Haskell mailing list