Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "&" mean in haskell?

Tags:

haskell

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?

like image 663
YYGX Avatar asked Sep 15 '25 20:09

YYGX


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.

like image 182
Bartek Banachewicz Avatar answered Sep 17 '25 18:09

Bartek Banachewicz


(&) 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
like image 37
Euge Avatar answered Sep 17 '25 18:09

Euge