[Haskell-beginners] Beginners Digest, Vol 41, Issue 30

Lee Short blackcat at pro-ns.net
Wed Nov 23 00:21:33 CET 2011


> On Tue, 22 Nov 2011 14:46:37 -0800
> Lee Short <blackcat at pro-ns.net> wrote:
>
>>  hlint gives me a parse error on a clause using DoIfThenElse, even 
>> if
>> I have the language pragma.  I don't see any hlint options to get
>> around that, are there any?
>>
>>  Is it considered good style to write code like this?
>>
>>  if "" == results
>>  then return True
>>  else return False
>>
>>  The obvious way rewrite below just seems clunky to me (though I can
>> see how others might prefer it to the code above).
>>
>>  return $ if "" == results
>>           then True
>>           else False
>
> You've just pressed one of my language-independent style hot
> buttons. Why on earth are you using an if/then/else here? What's 
> wrong
> with the straightforward:
>
>       return "" == results
>
> The expression results in a boolean, and it's even the one you want 
> to
> return. So why not return it?
>

 That's not my actual code, I was just using it as a simplified example 
 and didn't put a lot of thought into it.  My actual code is

 if delete /= ""
    then if exists
          then deleteFromTable req t key
          else return ()
    else if exists
          then updateTable req t key
          else insertTable req t

 I'd love to hear comments on how to make that more idiomatic, if 
 there's a way.




More information about the Beginners mailing list