I'm trying to reduce my confusion about Haskell's syntax and would like to find out what the separate namespaces are in Haskell.
Namespaces meaning syntactical namespaces corresponding to the various symbols tables the compiler manages, not name scopes defined in code.
For example:
I'm interested because I'm having trouble reading Haskell code (definitely more than with any other language) because I frequently have a hard time figuring out what exactly I'm looking at (especially with data/type constructors/type declarations).
Haskell seems to reuse a handful of syntactical constructs (esp. <name> <name> ...
) in many places and relies on context - just turns out that the compiler is a lot better at this than me...
The Haskell Report §1.4 says
There are six kinds of names in Haskell: those for variables and constructors denote values; those for type variables, type constructors, and type classes refer to entities related to the type system; and module names refer to modules. There are two constraints on naming:
- Names for variables and type variables are identifiers beginning with lowercase letters or underscore; the other four kinds of names are identifiers beginning with uppercase letters.
- An identifier must not be used as the name of a type constructor and a class in the same scope.
These are the only constraints; for example, Int may simultaneously be the name of a module, class, and constructor within a single scope.
The confusion can be avoided if you make sure you understand what you are reading:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With