Micheal, I think you mean<br><br>do <br> x <- if .. then ..<br> else ..<br> y <- if ... then.. <br> else... <br><br>etc etc<br><br><div><span class="gmail_quote">On 6/25/07, <b class="gmail_sendername">
Michael T. Richter</b> <<a href="mailto:email@example.com">firstname.lastname@example.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Now I've got a situation I can't figure out how to resolve. I want to have a set of actions which are executed sequentially, but which, before I even <b>start</b> to execute the first one, have been inspected for legality and/or plausibility. Consider this kind of sequence:
<tt> x <- performActionA</tt><br>
<tt> y <- performActionB</tt><br>
<tt> z <- performActionC</tt><br>
<tt> return $ calculateStuff x y z</tt><br>
Now obviously this is going to be in a monad of some kind. Were this a regular, run-of-the-mill program I'd just use the IO monad. But what I want to do instead is, before executing any of the perform* functions, check that the actions desired are actually
<b>permitted</b> (or possible) given a set of circumstances. For example let's say it's a permissions issue and performActionB can only be done if I'm root. If I'm not root I don't want performActionA done because I can't complete the transaction. (Maybe ActionA is non-reversible, say.) Or let's say this is code that's accessing databases on the network. If the network link to C can't be established, I don't want to screw around with A and B's links at all -- it's too expensive, too time-consuming or whatever.
Were I programming this in C, C++, Python, Ruby, etc. I could do this in my sleep. Functions are addresses (C/C++) or objects with an ID (Python/Ruby) so it's possible to take them and do some kind of check based on identities before executing things (although the scaffolding around this would be nontrivial in any of these languages except, possibly, Ruby). Functions in Haskell don't have this property, however, so I can't figure out what I'd do to perform similar work. I'm sure there's a way to do it, but I just can't see it.
<table cellpadding="0" cellspacing="0" width="100%">
<b>Michael T. Richter</b> <<a href="mailto:email@example.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">firstname.lastname@example.org</a>> (<b>GoogleTalk:</b> <a href="mailto:email@example.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
<i>I'm not schooled in the science of human factors, but I suspect surprise is not an element of a robust user interface. (Chip Rosenthal)</i>
<br>_______________________________________________<br>Haskell-Cafe mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">