When haskell pivot points need to work with extra “space”?

When defining lists, we use suspension points without additional spaces, such as:

Prelude> [3..5]
[3,4,5]
Prelude> [3 .. 5]
[3,4,5]

But for use with enumerations, additional spaces are required:

Prelude> [LT..GT]

<interactive>:2:2: Not in scope: ‘LT..’

<interactive>:2:2:
    A section must be enclosed in parentheses thus: (LT.. GT)
Prelude> [LT .. GT]
[LT,EQ,GT]

So the question is: is this a syntax rule in Haskell? Or are they related to implementations?

+4
source share
1 answer

LTis a valid module name, so you are referring to a function (.)by the name of this module (or an alias), not syntactic sugar for enumerations. Since you did not import LT(a module, not a data constructor), all of its hypothetical functions are beyond the scope.

, :

Prelude> import Prelude hiding (LT)
Prelude> import qualified Prelude as LT
Prelude LT> [LT..GT]

<interactive>:3:2:
    A section must be enclosed in parentheses thus: (LT.. GT)

. :

Prelude> [+ 1]
<interactive>:1:2:
    A section must be enclosed in parentheses thus: (+ 1)

Prelude> :t [(+ 1)]
[(+ 1)] :: Num a => [a -> a]

TL; DR: - , , . .

+7

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


All Articles