7

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.?
mb14
  • 22,276
  • 7
  • 60
  • 102
  • 3
    You can use `&&&` with functions, as in `((+10) &&& (+1)) 10`, which evaluates to `(20,11)` – Chris Taylor Mar 25 '14 at 10:34
  • 2
    Always remember there's nothing special whatsoever about function types in Haskell. `(->)` is a 2-argument type constructor no different from, say [`Array`](http://hackage.haskell.org/package/array-0.5.0.0/docs/Data-Array.html). Functions can be used like any other type, made instances of, stored as data in containers... only there's one extra thing you can do with them that's not oossible with other data, namely apply them to values. – leftaroundabout Mar 25 '14 at 11:24
  • 1
    Indeed I think the array combinators are much more commonly used with functions than with any other arrow type... – leftaroundabout Mar 25 '14 at 11:28

1 Answers1

15

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.

Tarmil
  • 11,177
  • 30
  • 35