REVISED: Tuesday, December 17, 2024
1. COQ'S FILE NAMING CONVENTIONS
Coq doesn't require any special naming conventions for files to import or export modules. The connection between files and modules is established through the Require and Require Import commands within Coq code, not through filename matching.
Here's a breakdown:
File Organization: You can organize your Coq code into any files you like (conventionally using the .v extension). For example, you might have MyModule.v, AnotherModule.v, and MainFile.v.
Module Definition: Within each .v file, you define modules using the Module ... End The name you give to the module within the Module declaration is crucial, not the filename.
Importing Modules: To use a module defined in another file, you use the Require or Require Import commands.
Require MyModule.: This command loads the file containing the MyModule definition. It makes the module name MyModule available, but you still need to use the qualified name (e.g., MyModule.my_nat) to access its contents.
Require Import MyModule.: This command loads the file and also imports the module into the current scope. This allows you to use the unqualified names (e.g., my_nat) directly.
Example:
Let's say you have two files:
MyModule.v:
Module MyModule.
Definition my_nat : nat := 5.
End MyModule.
MainFile.v:
Require Import MyModule. (* Or Require MyModule. *)
Compute my_nat. (* If you used Require Import *)
Compute MyModule.my_nat. (* Always works, even with just Require *)
In this example, the filename MyModule.v is arbitrary. You could rename it to SomethingElse.v as long as you change the Require command in MainFile.v accordingly:
(* If MyModule.v is renamed to SomethingElse.v *)
Require Import SomethingElse. (* Coq will look for SomethingElse.vo or SomethingElse.v *)
Compute MyModule.my_nat. (* Module name remains MyModule *)
Compilation:
When you compile your Coq project (using coqc), Coq creates compiled files (.vo files) that are used for faster loading. The Require commands instruct Coq to find these compiled files (or the source .v files if the .vo files are not available). Coq searches in the current directory and in directories specified by the -I flag (include paths).
2. CONCLUSION
Filenames are not directly used to resolve module names during import.
The Require (or Require Import) command, along with the module name specified in the Module declaration, is what connects files to modules.
Coq looks for .vo (compiled) or .v (source) files based on the required module name and the specified search paths.
This decoupling of filenames and module names provides flexibility in organizing your Coq projects.
3. REFERENCES
Bird, R. (2015). Thinking Functionally with Haskell. Cambridge, England: Cambridge University Press.
Davie, A. (1992). Introduction to Functional Programming Systems Using Haskell. Cambridge, England: Cambridge University Press.
Goerzen, J. & O'Sullivan, B. & Stewart, D. (2008). Real World Haskell. Sebastopol, CA: O'Reilly Media, Inc.
Hutton, G. (2007). Programming in Haskell. New York: Cambridge University Press.
Lipovača, M. (2011). Learn You a Haskell for Great Good!: A Beginner's Guide. San Francisco, CA: No Starch Press, Inc.
Pierce, Benjamin C., et al., editors. Logical Foundations. Vol. 1 of Software Foundations. Electronic Textbook, 2024. Version 6.7, http://softwarefoundations.cis.upenn.edu.
Thompson, S. (2011). The Craft of Functional Programming. Edinburgh Gate, Harlow, England: Pearson Education Limited.