Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

  • 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.?
like image 505
mb14 Avatar asked Mar 25 '14 09:03

mb14


1 Answers

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.

like image 76
Tarmil Avatar answered Oct 21 '22 10:10

Tarmil