Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What characters are permitted for Haskell operators?

Is there a complete list of allowed characters somewhere, or a rule that determines what can be used in an identifier vs an operator?

like image 612
Peter Hall Avatar asked May 11 '12 08:05

Peter Hall


People also ask

What is the OR operator in Haskell?

The OR operator is used to evaluate two expressions. We can write a double pipe || to use the OR operator. It will return either a True or a False based on the conditions.

What does -> mean in Haskell?

(->) is often called the "function arrow" or "function type constructor", and while it does have some special syntax, there's not that much special about it. It's essentially an infix type operator. Give it two types, and it gives you the type of functions between those types.

What does ++ do Haskell?

The ++ operator is the list concatenation operator which takes two lists as operands and "combines" them into a single list.


1 Answers

From the Haskell report, this is the syntax for allowed symbols:

a | b means a or b and

a<b> means a except b

special    ->   ( | ) | , | ; | [ | ] | `| { | }  symbol     ->   ascSymbol | uniSymbol<special | _ | : | " | '> ascSymbol  ->   ! | # | $ | % | & | * | + | . | / | < | = | > | ? | @                 \ | ^ | | | - | ~ uniSymbol  ->   any Unicode symbol or punctuation  

So, symbols are ASCII symbols or Unicode symbols except from those in special | _ | : | " | ', which are reserved.

Meaning the following characters can't be used: ( ) | , ; [ ] ` { } _ : " '

A few paragraphs below, the report gives the complete definition for Haskell operators:

varsym     -> ( symbol {symbol | :})<reservedop | dashes> consym     -> (: {symbol | :})<reservedop> reservedop -> .. | : | :: | = | \ | | | <- | -> | @ | ~ | => 

Operator symbols are formed from one or more symbol characters, as defined above, and are lexically distinguished into two namespaces (Section 1.4):

  • An operator symbol starting with a colon is a constructor.
  • An operator symbol starting with any other character is an ordinary identifier.

Notice that a colon by itself, ":", is reserved solely for use as the Haskell list constructor; this makes its treatment uniform with other parts of list syntax, such as "[]" and "[a,b]".

Other than the special syntax for prefix negation, all operators are infix, although each infix operator can be used in a section to yield partially applied operators (see Section 3.5). All of the standard infix operators are just predefined symbols and may be rebound.

like image 109
Riccardo T. Avatar answered Oct 02 '22 12:10

Riccardo T.