You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/0000-ghc-module-naming.rst
+66-17Lines changed: 66 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,27 +2,39 @@
2
2
3
3
**Module naming conventions for GHC base libraries**
4
4
5
-
Motivation
6
-
=============
5
+
Background and motivation
6
+
===========================
7
7
The accepted `Proposal #51: GHC base libraries <https://github.com/haskellfoundation/tech-proposals/blob/main/proposals/accepted/051-ghc-base-libraries.rst>`_
8
8
defines the following libraries:
9
9
10
10
* ``base``: the foundational library on which the rest of the ecosystem is based. Is API is carefully curated by the `Core Libraries Committee <https://github.com/haskell/core-libraries-committee>`_, and is kept rather stable.
11
11
12
12
* ``ghc-experimental``: the home of experimental extensions to GHC, usually ones proposed by the
Functions and types in here are usually candidates for later transfer into ``base``. It is user-facing (user are encouraged to depend on it), but its API is less stable than ``base``.
14
+
* Functions and types in here are usually candidates for later transfer into ``base``. But not necessarily: if a collection of functions is not adopted widely enough, it may not be proposed for a move to `base`.
15
+
* It is user-facing (user are encouraged to depend on it), but its API is less stable than ``base``.
15
16
16
17
* ``ghc-prim, ghc-internals`` (and perhaps others): define functions and data types used internally by GHC to support the API of ``base`` and ``ghc-experimental``.
17
-
These libraries come with no stability guarantees: they may change at short notice. (They do, however, follow the PVP.)
18
+
* These libraries come with no stability guarantees: they may change at short notice.
18
19
19
-
The question arises of what module names should be used. For example, suppose that all three exposed a module called ``Data.Tuple``. In principle that would be fine -- GHC allows you
20
+
In addition we already have:
21
+
22
+
* ``ghc``: this library exposes GHC as a library, through the (currently ill-defined) GHC API.
23
+
24
+
All these libraries follow the Haskell Package Versioning Policy (PVP).
25
+
26
+
The question arises of *what module names should be used*. For example, suppose that all three exposed a module called ``Data.Tuple``. In principle that would be fine -- GHC allows you
20
27
to use the package name in the ``import`` statement, to disambiguate. But it's *extremely* confusing. This proposal articulates a set of conventions to
21
28
help us design module names.
22
29
23
30
The proposal
24
31
============
25
32
33
+
This proposal is split into four for easier discussion. Each sub-proposal builds on the
34
+
earlier ones -- they are increments, not alternatives.
35
+
36
+
The goals of this proposal are deliberately limited to establish naming conventions. We propose no new mechanisms.
37
+
26
38
Proposal 1
27
39
-----------
28
40
@@ -49,12 +61,56 @@ Proposal 3
49
61
The current ``base`` API exposes many modules starting with ``GHC.*``, so the proposed conventions could only
50
62
apply to *new* modules.
51
63
52
-
* Over time, and with the agreement and support of the Core Libraries Committee, we should seek to remove ``GHC.*`` modules
53
-
from ``base``, either exposing their desired API through a stable, CLC-curated, module in ``base``; or removing it altogether. Of course
54
-
there would be a significant deprecation cycle, to allow client libraries to adapt.
64
+
* Over time, and with the agreement and support of the Core Libraries Committee, we may remove some ``GHC.*`` modules
65
+
from ``base``, especially ones that are barely used, or are manifestly "internal" (i.e. part of the implementation
66
+
of other, more public functions.
67
+
Of course there would be a significant deprecation cycle, to allow client libraries to adapt.
68
+
69
+
Proposal 3 only expresses a direction of travel. We will have to see what the CLC's attitude is,
70
+
and what the Haskell community thinks. Anything that disturbs the API of base needs to be considered
71
+
rather carefully.
72
+
73
+
74
+
Proposal 4
75
+
------------
76
+
77
+
* The public API of package ``ghc`` (GHC as a library) should have modules of form ``GhcAPI.*``.
78
+
79
+
All of the modules in package ``ghc`` currently start with ``GHC.*`` which correctly signals that they are part of GHC's internals.
80
+
As part of the GHC API redesign (a HF project in its own right, currently stalled) it would be very helpfult
81
+
to modules with stable APIs, and a new prefix, such as ``GhcAPI.*``.
82
+
83
+
84
+
Timescale
85
+
==========
86
+
The first release of GHC with `ghc-experimental` and `ghc-internals` will be GHC 9.10, which expect to
87
+
release in early 2024. It would be good to establish naming conventions for modules well before this date.
88
+
89
+
Example lifecycle
90
+
===================
91
+
92
+
By way of example, consider the ``HasField`` class, which supports overloaded record fields.
93
+
It is currently defined in ``base:GHC.Records``, which is an odd module to have to import.
94
+
Moreover there is
95
+
more than one GHC proposal that suggest changes to its design (e.g. see `GHC Proposal 158 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0158-record-set-field.rst>`_); it is not nearly as stable as most of ``base``
96
+
97
+
If ``ghc-experimental`` had existed we would have put it in ``ghc-experimental:Experimental.Records``.
98
+
That would have made it clear that the design of overloaded records still evolving.
99
+
Once the design becomes settled and stable, it could move to ``base``, perhaps in a module like ``Data.Records``.
100
+
101
+
Other similar examples include
102
+
* The tuple proposal of `GHC Proposal 475 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0475-tuple-syntax.rst>`_
103
+
* The `DataToTag CLC proposal <https://github.com/haskell/core-libraries-committee/issues/104>`_ would have been easier to expose through ``ghc-experimental`` in the first instance.
55
104
56
105
Alternatives
57
106
==============
107
+
* We could dispute Proposal 1: one could imagine deliberately naming modules in ``ghc-experimental`` with the
108
+
same module name as their eventual expected (by someone) home in ``base``. The goal would be to reduce impact if and when
109
+
the module moves from ``ghc-experimental`` to ``base``. For example, we might add ``Data.Tuple`` to ``ghc-experimental`` containing the new type constructors ``Tuple2``, ``Tuple3`` etc that are proposed in `GHC Proposal 475 <https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0475-tuple-syntax.rst>`_. However:
110
+
111
+
* In the meantime there are two modules both called ``Data.Tuple``. This is bad. Which one does ``import Data.Tuple`` import? (Look at the Cabal file, perhaps?) How can I import both? (Package-qualified imports perhaps.) So it will really only help in the case of a brand-new module, not already in ``base``.
112
+
* It loses the explicit cue given by ``import Experimental.Data.Tuple``.
113
+
58
114
* We could use ``GHC.*`` for modules in ``ghc-experimental``, and maybe ``GHC.Internals.*`` for module in ``ghc-internals``. But
59
115
60
116
* There are two sorts of GHC-specific-ness to consider:
@@ -65,17 +121,10 @@ Alternatives
65
121
66
122
* It would be a huge upheaval (with impact on users) to rename hundreds of modules in ``ghc-internals``.
67
123
124
+
* We could use ``GHC.Experimental.*`` for modules in ``ghc-experimental``. But that seems a bit backwards: ``GHC.Tuple`` (in ``ghc-internals``) would look more stable (less experimental) than ``GHC.Experimental.Tuple`` in ``ghc-experimental``; but the reverse is the case.
125
+
68
126
* We could use a suffix ``*.Internals`` or ``*.Experimental`` instead of a prefix. But
69
127
* This sort of naming is conventionally used to distinguish modules *within* a package, not *between* packages.
70
128
* It would still suffer from the cost of renaming hundreds of modules in ``ghc-internals``
71
129
72
-
Discussion
73
-
============
74
-
What should we do about the ``ghc`` package, which exposes GHC as a library, through the GHC API?
75
-
It wouldn't really make sense to call it ``Experimental.*``. And yet, under the above proposals, ``GHC.*`` connotes
76
-
"internal, unstable" which should not be true of the GHC API (although it is today).
77
-
78
-
Perhaps, as part of the GHC API redesign (a HF project in its own right) we can define modules with
79
-
stable APIs, and a new prefix, such as ``GhcAPI.*``?
0 commit comments