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

On Tue, 22 Nov 2011 14:46:37 -0800 Lee Short
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.

On Wednesday 23 November 2011, 00:21:33, Lee Short wrote:
That's not my actual code, I was just using it as a simplified example
Glad to read that.
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.
Hmm, harder, much harder. You can replace the if exists then deleteFromTable req t key else return () with when exists (deleteFromTable req t key) and instead of comparing to "", you can use null, so if null delete then if exists then updateTable req t key else insertTable req t else when exists (deleteFromTable req t key) I would recommend the when. Concerning the null vs. /= "", I prefer null, but I'm not religious about it.
participants (2)
-
Daniel Fischer
-
Lee Short