[Haskell-cafe] YAWQ (Yet Another Wash Question)

Jules Bean jules at jellybean.co.uk
Thu Feb 24 12:53:29 EST 2005


On 24 Feb 2005, at 17:33, John Goerzen wrote:

> On Thu, Feb 24, 2005 at 05:22:40PM +0000, Jules Bean wrote:
>>
>> On 24 Feb 2005, at 16:42, John Goerzen wrote:
>>
>>> ... do if cond
>>>          then x <- textInputField ...
>>>          else ()
>>>       ...
>>>       submit ...
>>>
>>> Well, two problems there... first, the scope of the x doesn't reach 
>>> to
>>> the submit.  Second, there's a type issue.  So I thought maybe I 
>>> could
>>> figure out something like this:
>>>
>>
>> Well, how could this possibly work (that is, how could 'x' be visible
>> at the point of submission)? If you go down the 'else' branch, what
>> value should x have?
>
> I'm assuming I would have two different calls to submit, one for the
> case where cond is true (that includes x), and one for the case where
> cond is false (that omits it).

Well saying that makes me think that the submit itself should be in the 
branches of the if ... then ... else ...

>> Once you know what value x is supposed to have down the else branch
>> then you will be able to do something like:
>>
>> x <- if cond then textInputField ... else return ...
>
> but I have to return something with the same type as textInputField, 
> and
> the only things with that type are other input fields.  I don't want
> something else there.  I want nothing there.

Well, that was a simplified example. You could replace textInputField 
with do { y <- textInputField ; return SomeComplexExpressionUsingY }. 
It may be that you want to use a Maybe type (as you suggested in your 
original mail), or perhaps an Either type for the two alternatives.

Jules



More information about the Haskell-Cafe mailing list