In many languages, submodules are used mostly for organization and namespace management, however Racket’s module system is more advanced than that. Other than the common examples of test
and main
, what would be some recommended use cases for submodules?
I use submodules to embed implementations in DSLs. For example, I might embed a module containing a GLSL program encoded as s-expressions and then require
(or, more likely, local-require
) it to get GLSL-formatted source strings. It’s also pretty common to find Typed Racket submodules embedded in untyped Racket for extra performance.
the contract-out
form allows to make a submodule that provides the identifiers without contracts. so basically most of the time you’ll see it to limit the amount of provided identifiers, there is also some “hacks” you’ll see around with submodules
I use a drracket
submodule to have a drracket-specific behaviour, like plots.
Quickscript uses a submodule so that it’s fast to require only some basic properties of the scripts without requiring the whole code, to build the menus