[Haskell-cafe] IO and Wash

Simon Marlow simonmar at microsoft.com
Wed Feb 16 09:56:11 EST 2005


On 16 February 2005 14:30, John Goerzen wrote:

> On Wed, Feb 16, 2005 at 07:31:07AM +0100, Tomasz Zielonka wrote:
>>> verbatim.  Any ideas?
>> 
>> I have never used table_io. maybe there's a bug in it. Hmmm, it seems
>> to be conceptually wrong. The single purpose of table_io seems to be
>> to avoid keeping the result of an IO action in the log. But how is
>> WASH going to recreate it when it's needed again as in your example?
> 
> Ahh, I think I understand what you're saying...  table_io is not
> supposed to be unsafe; that is, it should work without saving data in
> the log even if the input would be different on a different session.
> But yes, if the validation fails, there would be no way to do that
> save re-reading the input.
> 
> It sounds like, in my case, unsafe_io would be better.  My input
> should never change across a single session.
> 
> The next question is this: the I/O really only needs to be done once.
> Once the user has selected an item, that's enough.  If my
> understanding is correct, on each subsequent screen in my
> application, Wash will follow through the entire call history, and
> will run the I/O again even if not needed.  Is that correct?  Or does
> the unsafe_io prevent that? 

You can avoid lots of unnecessary state-saving by judicious use of
WASH's 'once' function.  eg.

  ...
  r <- once ( ... lots of IO ... )
  ...

will save the value of r in the log, and not repeat the entire inner
action each time the script is run.  In fact, it might be helpful to
note that 

  io = once . unsafe_io

Cheers,
	Simon


More information about the Haskell-Cafe mailing list