What does the% operator mean in Haskell?

I want to know what the Haskell operator% does. Hard to find on google, I couldn't find it in the Haskell report.

I saw how it was used in this piece of code:

 fi=zz.bu
 bu=zz.(:).(++"zz")
 []#zz=zz;zz#__=zz
 zZ%zz=zZ zz$zZ%zz
 zz=(([[],[]]++).)
 zZ=zipWith;z=zZ((#).show)[1..]$zZ(++)(bu%"Fi")(fi%"Bu")

      

taken from: https://codegolf.stackexchange.com/questions/88/obfuscated-fizzbuzz-golf/110#110

+3


source to share


2 answers


Here is the relevant section of the Haskell report:

Haskell provides a special syntax to support infix notation. An operator is a function that can be applied using infix syntax (section 3.4) or partially applied using a section (section 3.5).

An operator is either an operator symbol, for example +

, or $$

, or it is a regular identifier enclosed in backquotes, such as `op`. For example, instead of writing a prefix application, op x y

you can write an infix application x `op` y

. If `op`

no commit declaration is specified for it, it defaults to highest precedence and left associativity (see Section 4.4.2).

The operator double character can be converted to a regular identifier by enclosing it in parentheses. For example, it is (+) x y

equivalent x + y

, but it is foldr (*) 1 xs

equivalent foldr (\x y -> x * y) 1 xs

.



That is, in Haskell, there is nothing special about "operators" other than their syntax. A function whose name is composed of the default infix characters, a function whose name is the default alphanumeric prefix, and either can be used in a different style with a little extra syntax.

By the way, since it is often impossible to search by operator names using Google to find operators declared in standard libraries, there are two search engines specifically for finding things in Hackage.

+8


source


In general, we can define a new function foo

as follows:

foo a b c = (something involving a, b, and c)

      



Likewise, we can define a binary operator %

(constructed from any combination of character symbols) as follows:

a % b = (something involving a and b)

      

+5


source







All Articles