Haskell language report: reservedid definition

Good, that's why I played all day with the Haskell Language Report (2010) and found all kinds of โ€œinterestingโ€ edges. Material that, in your opinion, should be a mistake, but which is actually allowed.

In particular, consider the following excerpt from a lexical syntax reference (section 10.2):

reservedid โ†’ case | class | data | default | deriving | do | else | foreign | if | import | in | infix | infixl | | infixr | instance | let | module | newtype | of | then | type | where | _ 

You may see qualified in this list & hellip; But he is not. (Not as or hiding , for that matter.)

Now I'm curious and hellip; Is this a random observation in the Report? Or is it a deliberate design decision?

The GHC seems to at least follow the letter of the specification, as it will gladly allow you to define a variable whose name is essentially qualified . Strange, but true. Thus, it seems that this name is only "special" in one context. On the contrary, you can never name a module variable. We could make this word special only at the beginning of the & hellip; but we did not.

+6
source share
2 answers

qualified , as and hiding are found only in certain places as keywords, so they can be used as variable names.

  • qualified only happens after import .
  • as occurs only after import qualified PACKAGE
  • hiding only happens after import [qualified] PACKAGE [as NAME]

I understand what you mean by pointing out that module may be one of these keywords related to the placement, but it seems counterintuitive to call anything module . Maybe the previous version of Haskell allows several modules in a single file?

You can say the same for qualified and hiding , but I often used as , for example:

 zip [] _ = [] zip _ [] = [] zip (a:as) (b:bs) = (a, b) : zip as bs 

So, with that in mind, I think this is really a design decision that I think can include many languages โ€‹โ€‹*.

It may be worth noting that deriving may be one of these words because it always follows the data declaration, as well as foreign , since it is reserved only with the FFI extension.


* Especially javascript, with it is a huge list of mostly meaningless reserved words !

+8
source

First, the keywords โ€œhow,โ€ โ€œhide,โ€ and โ€œqualifyโ€ were not in the original Haskell definition. When they were added, they were not made into reserved words for backward compatibility. Adding reserved words is a good way to break code. It was a very deliberate decision.

Secondly, as far as I know, Haskell does not prohibit multiple modules per file. The spec just doesn't talk about files. (But I do not know any implementation that allows this.)

+4
source

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


All Articles