List comprehension question

So hlint suggests that I convert the line checked = if ival==input then [("checked","checked")] else [] to checked = [("checked","checked") | ival==input] I'm not really sure why this works. Is there some implicit list being filtered by ival==input? What's going on? thanks Lee

On Wednesday 23 November 2011, 01:08:26, Lee Short wrote:
So hlint suggests that I convert the line
checked = if ival==input then [("checked","checked")] else []
to
checked = [("checked","checked") | ival==input]
I'm not really sure why this works. Is there some implicit list being filtered by ival==input? What's going on?
A list comprehension [expression | condition] desugars to if condition then [expression] else [] IMO, that's one of the places where hlint doesn't suggest an improvement.

Hi Daniel already gave you an answer. The details on how list comprehension is desugared can be found in section 3.11 of the Haskell report [1]. I am just mentioning this because I really want to encourage people to read the language standard when hitting such a question. Not saying one shouldn't post questions here. But it typically saves _you_ a lot of time to just read the answer up. And if the standard is well written - which it IMO is for Haskell - you even get a complete, concise and unambigous answer which extands your knowledge of the language. Greetings Alex [1] http://www.haskell.org/onlinereport/exps.html#sect3.11
participants (3)
-
Alexander Bernauer
-
Daniel Fischer
-
Lee Short