-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module names should be required to match filenames. #2670
Comments
Don't you mean it's 4? Foo.value should be the value defined in the module Foo in the file Bar.idr, right? That's the whole point. |
See? I even confused myself. :-) |
If one accepts the idea that file names should match module names (which I do), why do we need the |
I suppose the exception would be source files that don't declare an explicit module (which seem to automatically get named I think your point is interesting nonetheless. |
Like Haskell and Rust we have package files that could serve to tell where modules are.
Rust allows multiple nested modules per file, which would be impossible with this restriction. In Haskell it's also just a convention. I don't see why we couldn't handle this by convention. I don't like locking into a module == File identity. I'd like more flexible and parameterizable modules. Also, the title is misleading, "Module names should be required to match filenames." would require all main programs to be named Main.idr. I hope nobody is advocating that. |
I also would like flexible and parametrizable modules. But at the moment we have:
On the top of this we have export modifiers, hiding directives which take specific arguments but modify the export status of whole module names, upper case and lower case conventions for implicit parameters name resolution rules ... I admit I do not fully understand the problems these constructs are designed to address but I have the impression that having
I would not mind if name resolution conventions would require a name
I do not advocate that but I would not have anything against that either. What is wrong with files containing main programs to be called Main.idr? |
When I met Haskell I was annoyed by the redundancy of file and module names. To move or rename a source folder [or module name], one needs to update all the module headers in all the files in that folder recursively. It is an unnecessary inconvenience. |
@almale's comment suggests a compromise solution. What if...
Personally, I'd rather not allow for the latter (convention over configuration) and eventually unify modules and namespaces. But I thought I'd suggest it. |
Cliff L. Biffle [email protected] wrote:
What would be the benefits of overriding file names?
|
shrug Attempting to short-circuit objections like @melted's. Though I actually think he's arguing with a strawman; I'll respond directly. |
True, and this could perhaps provide a back-door for people who insist on having filenames that don't match their module names. That being said, I'm not convinced that a detailed package file should be a prerequisite to a project (that is, there ought to be a default mapping from imported name to filesystem location).
I think you misunderstand what I was proposing. Banning this was certainly not my intent, and I would love to (1) allow nested modules and (2) eliminate namespaces. I didn't go into detail on the behavior of nested modules since they don't currently exist in Idris. In the presence of nested modules, I'd rephrase my suggestion as: the top level module in a file ought to match its filename / path relative to a source root.
Me too.
I'm open to suggestions for better titles, it seems much of my post misled you. I consider Idris's assumption that the main function lives in a module called |
I have added three files to https://github.com/nicolabotta/SeqDecProbs/tree/master/frameworks/14-: The files are meant to provide a small but realistic example to help the current discussion on module and file names being more concrete. At the same time, I wanted to contribute to the (I believe, closely related) problem of "Where to put proofs of e.g. base?" originally initiated by Cliff on idris-lang. The idea behind the example is that a library developer wants to implement a data type representing fractions equipped with standard operations: addition, multiplications, etc. I have put my (dirty) contribution in First, there is a problem of splitting and namegiving. Is it appropriate to split specification and implementation into different files, modules, namespaces? Considering that a given specification can, in general, be fulfilled by different implementations, splitting the two would seem quite natural. But which Idris constructs should we use to express such distinction? Modules, namespaces, type classes? Or should we rather rely on files and directory names? Second, there is a problem of hiding directives and name resolution rules: I have initially tried to put the content of the three files in a single module and under three different namespaces and I failed. I have tried, in
to allow me to specify infix addition and multiplication operators for fractions. Alas, this does not type check because Third, there is a problem of maintainability. If we split specification, implementation independent properties, implementation(s), implementation(s) dependent properties in different files or modules, we might easily end up with circular |
I think that |
Currently, imports work in terms of file paths, but qualified references work in terms of module names. The two have no relation.
As an example, consider these two files:
Foo.idr
Bar.idr
Now consider the use of these modules:
What is the value of
Foo.value
? It is 4.While this may seem somewhat contrived, I've run into this when rearranging a codebase. It's easy to
git mv
some files (possibly even permuting their names) and forget to update themodule
declarations.Clearly,
import
must follow the filesystem; to do otherwise would require e.g. maintaining a database of which modules live where.I suggest that the behavior of
import
be preserved, but the compiler reject with an error any file thatmodule
declaration, andimport
, that doesn't match its module name, per the usual dot-for-separator substitution.Precedent in existing languages (Java, Rust, Haskell) suggests that such a requirement is unlikely to be onerous.
The text was updated successfully, but these errors were encountered: