What characters are allowed for Haskell statements?

Is there somewhere a complete list of valid characters or a rule that defines what can be used in an identifier or statement?

+65
operators syntax haskell
May 11 '12 at 8:43
source share
3 answers

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

a | b 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 

Thus, characters are ASCII characters or Unicode characters, with the exception of characters in special | _ | : | " | ' special | _ | : | " | ' special | _ | : | " | ' which are reserved.

This means that the following characters cannot be used: | , ; [ ] ' { } _ : " ' | , ; [ ] ' { } _ : " '

In a few paragraphs below, the report contains a complete definition of Haskell statements:

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

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

  • An operator character starting with a colon is a constructor.
  • An operator character starting with any other character is a regular identifier.

Note that the colon itself, ":" is reserved exclusively for use as a Haskell List Constructor; this makes its treatment consistent with other parts of the list syntax, such as "[]" and "[a, b]".

Except for the special syntax for negating a prefix, all infix operators, although each infix operator can be used in a section to obtain partially applicable operators (see section 3.5). All standard Infix operators are just predefined characters and can be a rebound.

+59
May 11 '12 at 9:08 a.m.
source share

From Haskell 2010 Report ยง2.4 :

Operator characters are formed from one or more character characters ...

ยง2.2 defines character characters as any of !#$%&*+./<=>?@\^|-~: or "any [non-ascii] Unicode character or punctuation".

+31
May 11 '12 at 8:53
source share



All Articles