What does "&" mean in haskell?

Viewed 237

I am new to haskell. Somebody gave me a symbol and a formula: m & n = n m But "&" can't be read by ghci,and we searched the Internet and found no information. Could anyone tell me what the & means?

2 Answers

It's an identifier without any special meaning, so it means whatever you want it to. E.g. in Lens & is used as flip ($) for convenience, like so:

let x = (1,2)
  & _1 +~ 1
  & _2 +~ 2

-- x = (2,4)

This also fits your definition of m & n = n m (they're equivalent). Any other library can use it for whatever, and if you use a better search engine, you'll find numerous ones.

(&) operator is defined in Data.Function package. To use it in ghci you have to import Data.Function

Then you can use it with the meaning given by the formula you posted.

> pi & cos
-1.0

Same as:

> cos pi
-1.0
Related