Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upShould a module importing itself be disallowed? #3079
Comments
This comment has been minimized.
This comment has been minimized.
|
@natefaubion pointed out that this import doesn't appear in the generated JavaScript in Try PureScript, so maybe this is just an issue for |
This comment has been minimized.
This comment has been minimized.
|
The compiler allows the import, but you can't reference anything in it (if qualified), and no code is generated for it. |
paf31
added
bug
modules
labels
Sep 20, 2017
paf31
added this to the Approved milestone
Sep 20, 2017
This comment has been minimized.
This comment has been minimized.
|
A possible alternative: could importing and referring to the current module just be syntax sugar? module Abc where
import Abc as Abc
import Def as Def
foo :: String
foo = "hi"
bar :: String
bar = Def.qux <> Abc.foo -- `Abc.foo` just turns into `foo` on compilation.It seems ridiculous at face value, but it's useful in some code-generation scenarios where it's a pain to keep track of the "current" module. If you always blindly import what you need in each place (and if the tree of imports doesn't contain any cycles outside of self-references), then you don't have to do the current-context accounting. (I'm aware this use-case probably isn't enough to swing it. We're taking advantage of the above behaviour for some Haskell codegen, and switched to open-imports-with-compiler-warnings-disabled for the PureScript side of things until we can do a proper job of the accounting.) |
paulyoung commentedSep 19, 2017
We use PureScript with webpack via
purs-loaderandcircular-dependency-plugin, and started seeing this warning:Sure enough,
purescript-formattershas an import statement for itself with a function defined in the same module:https://github.com/slamdata/purescript-formatters/blob/859e9f5c7d507441d495870acbb06380940eda97/src/Data/Formatter/Parser/Number.purs#L12
Should this be disallowed?