When running hlint over my program it reported an error for
\x -> [x]
and suggested the alternative form
(: [])
What is there erroneous according to hlint about the first form, and thus why should I use the (less readable) second option?
Edit
(added hlint explicitly to the question)
My question lies not so much with what the difference is (I do understand both of them) in lexical point of view. My problem is that I do not understand why hlint is marking it as an error. Is there for example a difference in laziness? Furthermore why is the previous thought of as erroneous by hlint while \x -> Just x
raises only a warning.
A common question, to which I've just added an answer in the HLint manual. It says:
While the difference is personal taste, sometimes I change my mind. Looking at the two examples in this thread,
(:[])
seems a relatively "complex" hint - you are breaking down the syntactic sugar of[x]
tox:[]
, which in some ways is peeling through the abstraction of a list as a generic container, if you never pattern match on it. In contrast\x -> Just x
toJust
always seems like a good idea. Therefore, in HLint-1.8.43 (just released) I have made the first a warning, and the second an error.