haskellarrowshlint

HLint : use &&& suggestion advice


I ran HLint on a little project and it suggested me to use &&&.

Example :

>>> cat st.hs
f = (+) 10
g = (+) 1

main = print $ (\x -> (f x, g x)) 5
>>> hlint st.hs
st.hs:4:17: Warning: Use &&&
Found:
  \ x -> (f x, g x)
Why not:
  f Control.Arrow.&&& g

1 suggestion

I understand the \x -> (f x, g x) is a pattern and appreciate the suggestion. However Control.Arrow.&&& doesn't take normal functions but arrow, so I can't just use &&& as suggested.

So what is the recommended way in that situation ?


Solution

  • Arrow is a type class, of which (->) is an instance (see here under "Instances", and here for the implementation). This means that you can directly use arrow operators such as (&&&) with functions.