git.iko.soy/rowtype-yoga/purescript-native
on db2dd21 help sign in
57 lines 1.7 kB history raw
1Modules
2=======
4All code in PureScript is contained in a module. Modules are introduced using the ``module`` keyword::
6 module A where
7
8 id x = x
10When referencing values or data types in another module, names may be qualified by using a dot::
12 module B where
14 foo = A.id
16Importing Modules
17-----------------
19A module can be imported using the ``import`` keyword. This will create aliases for all of the values and types in the imported module::
21 module B where
23 import A
25Alternatively, a list of names to import can be provided in parentheses::
27 module B where
29 import A (runFoo)
31Values, type constructors and data constructors can all be explicitly imported. A type constructor should be followed by a list of associated data constructors to import in parentheses. A double dot (``..``) can be used to import all data constructors for a given type constructor::
33 module B where
35 import A (runFoo, Foo(..), Bar(Bar))
37Qualified Imports
38-----------------
40Modules can also be imported `qualified`, which means that their names will not be brought directly into scope, but rather, aliased to a different module name. This can be helpful when avoiding naming conflicts::
42 module Main where
44 import qualified Data.Array as A
46 null = ...
48Here, the name ``null`` would ordinarily conflict with ``null`` from ``Data.Array``, but the qualified import solves this problem. ``Data.Array.null`` can be referenced using ``A.null`` instead.
50Module Exports
51--------------
53Module exports can be restricted to a set of names by providing that set in parentheses in the module declaration::
55 module A (runFoo, Foo(..)) where
57The types of names which can be exported is the same as for module imports.