What symbol namespaces exist in Haskell?

I am trying to reduce my confusion in Haskell syntax and would like to know what separate namespaces are in Haskell.

Namespaces means syntactic namespaces that correspond to the tables of various characters controlled by the compiler, and not the names of the areas defined in the code.

For instance:

  • Value names (e.g. function names)
  • Data constructors
  • Type constructors
  • Type parameters (in type definitions)
  • instances?
  • ...

I am interested because I have problems reading Haskell code (definitely more than with any other language), because I often find it difficult to understand exactly what I am looking for (especially with constructors / data types / statement type).

Haskell seems to be reusing several syntax constructs (esp. <name> <name> ... ) in many places and relies on context - it just turns out that the compiler is much better than me ...

+6
source share
2 answers

Haskell ยง1.4 report says

There are six types of names in Haskell: for variables, and constructors denote values; those for type variables, type constructors and type classes relate to objects belonging to the type system; and module names refer to modules. There are two naming restrictions:

  • Variable names and type variables are identifiers starting with lowercase letters or underscores; the other four kinds of names are identifiers starting with capital letters.
  • The identifier should not be used as the name of the type constructor and class in the same scope.

These are the only limitations; for example, Int can simultaneously be the name of a module, class, and constructor within the same scope.

+13
source

Confusion can be avoided if you make sure you understand what you are reading:

  • expression: here, each uppercase name is a data constructor or qualified variable or constructor, while lowercase is a value
  • a type: here, each uppercase name is a type constructor or class name, while lowercase names are type variables.
+5
source

Source: https://habr.com/ru/post/916129/


All Articles