I always wrote my list-producing recursive functions in this format:
recursiveFunc :: [a] -> [b]
recursiveFunc (x:xs) = [change x] ++ resursiveFunc xs where
change :: a -> b
change x = ...
I realize any function like the above could be written for the a -> b case and then simply maped over a set [a], but please take this watered-down situation as an example.
HLint suggests replacing [change x] ++ recursiveFunc xs with change x : recursiveFunc xs.
Is this suggestion purely aesthetic, or is there some effect on how Haskell executes the function?
When using
[change x] ++ recursiveFunc xsyou create a superfluous one-element list, which is then taken apart by the++function. Using:that doesn’t happen.Plus
++is a function which then will use the:constructor. When you use:directly, there’s no need to invoke a function.So using
:is more efficient in theory (the compiler might optimize those differences away, though).