Skip to content

Commit 80780ad

Browse files
committed
Revsions following discussion
1 parent 3fdee50 commit 80780ad

File tree

1 file changed

+66
-17
lines changed

1 file changed

+66
-17
lines changed

proposals/0000-ghc-module-naming.rst

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,39 @@
22

33
**Module naming conventions for GHC base libraries**
44

5-
Motivation
6-
=============
5+
Background and motivation
6+
===========================
77
The accepted `Proposal #51: GHC base libraries <https://github.com/haskellfoundation/tech-proposals/blob/main/proposals/accepted/051-ghc-base-libraries.rst>`_
88
defines the following libraries:
99

1010
* ``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.
1111

1212
* ``ghc-experimental``: the home of experimental extensions to GHC, usually ones proposed by the
1313
`GHC Steering Committee <https://github.com/ghc-proposals/ghc-proposals/>`_.
14-
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``.
1516

1617
* ``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.
1819

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
2027
to use the package name in the ``import`` statement, to disambiguate. But it's *extremely* confusing. This proposal articulates a set of conventions to
2128
help us design module names.
2229

2330
The proposal
2431
============
2532

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+
2638
Proposal 1
2739
-----------
2840

@@ -49,12 +61,56 @@ Proposal 3
4961
The current ``base`` API exposes many modules starting with ``GHC.*``, so the proposed conventions could only
5062
apply to *new* modules.
5163

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.
55104

56105
Alternatives
57106
==============
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+
58114
* We could use ``GHC.*`` for modules in ``ghc-experimental``, and maybe ``GHC.Internals.*`` for module in ``ghc-internals``. But
59115

60116
* There are two sorts of GHC-specific-ness to consider:
@@ -65,17 +121,10 @@ Alternatives
65121

66122
* It would be a huge upheaval (with impact on users) to rename hundreds of modules in ``ghc-internals``.
67123

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+
68126
* We could use a suffix ``*.Internals`` or ``*.Experimental`` instead of a prefix. But
69127
* This sort of naming is conventionally used to distinguish modules *within* a package, not *between* packages.
70128
* It would still suffer from the cost of renaming hundreds of modules in ``ghc-internals``
71129

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.*``?
80-
81130

0 commit comments

Comments
 (0)