When defining lists, we use suspension points without extra spaces like this:
Prelude> [3..5]
[3,4,5]
Prelude> [3 .. 5]
[3,4,5]
But used with enumerations seems extra 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 question is: is it a syntax rule in Haskell? Or related to implementations?
LT
is a valid module name, and therefore you refer to the function (.)
in that module name (or alias), not the syntactic sugar for enumerations. Since you didn't import LT
(the module, not the data constructor), all of it's hypothetical functions are out of scope.
Here's a bogus example that does not lead to an out of scope error:
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)
Even with the parentheses it wouldn't type check. The section error can also be achieved with a single list:
Prelude> [+ 1]
<interactive>:1:2:
A section must be enclosed in parentheses thus: (+ 1)
Prelude> :t [(+ 1)]
[(+ 1)] :: Num a => [a -> a]
TL;DR: Unless you want to specify something from another module, make sure have some space between .
and a valid module name.
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