Question

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 ?

  • define my own &&& operator on function ?
  • use arrow and do something like (arr f) &&& (arr g) but I even don't know how evaluate it ?
  • ignore Hlint on that particular occasion.?
Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top