There’s a tension between “batteries included” (e.g., Python) and official Haskell (e.g., Haskell 98, Haskell 2010). My opinion tends more toward making an updated, streamlined prelude and leaving out all of the GHC-specific parts of the current base. We should aim for a stable prelude instead of one that changes as quickly as base has changed. In general, it is time to admit that Haskell is no longer just a research project, where the language developers can do whatever they want without concern for existing code. Instead, keep the leading edge stuff in optional libraries that can be versioned if necessary. Then, make an effort to ease the transition to newer versions to allow for organic growth and change.
Personally I am very hyped on this idea in almost every respect. There are still a few areas that need to be fleshed out in order to make this proposal concrete:
Who maintains this new
base-purepackage? Will it be a continuation (and slight expansion) of the Core Libraries Committee work? If so, we’ll need to coordinate with folks like @chessai in order to pin down what needs to happen on the CLC side to incorporate such a package into its charter.
What kind of stability guarantees are we planning for such a
base? I would assume that this would have the same long-term guarantee as
base, but we should be explicit.
At what point do we intend this new safe base to be the real base that we offer to users? What constitutes “critical mass”, or, is this even an issue? We’ll have to figure out a safe time, perhaps with a major GHC release, to do the switch so that this is done with minimal breakage to the Hackage and Stacakage ecosystems.
Suggestion: freeze “base” and call the new prelude by a new name. Eventually, just let “base” wither away.
(disclaimer: I talked about this in private with Ben but it deemed necessary to post that publicly)
(TL;DR: We need to avoid pleasing every possible group of users at once, and as such the better we can figure out our target group, the better the end result will be, that is why we need to split some of the changes we would all like to see between
base and a new
At the moment, what the Prelude is trying to achieve is unclear beyond the simple “default exports”. It does not particularly help neither library writers, beginners, compiler engineers, nor application developers.
As a consequence, we have seen many alternative preludes trying to address the concerns of those categories. We have the preludes that pride themselves as being an application development framework, with effect tracking, logging, database, etc), those who provide better data-structures and re-exports other packages, and so on.
As such, I think it is important to have this discussion about a prevalent alternative prelude under the prism of “Which category do we aim to serve?”. The library writers certainly may not want to have
transformers re-exported! But they want
head :: NonEmpty a, which is also something that would benefit the beginners! The application developers may, on the other hand, need to have a more off-the-shelf access to ReaderT and
Text-first environments, as well as having Vector and HashMap coming in handy.
Now, the reader may think “Well, isn’t that what the Haskell Platform was about?”, to which I will reply that whilst the Haskell Platform did in fact provide a set of blessed libraries, they were also pre-compiled and efforts were invested to ease the burden of development on the tooling/package handling side of things.
To directly reply to some of Ben’s points:
[…] away with partial functions and known laziness foot-guns (e.g. foldl)
I think we can have this problem solved in
re-exports the libraries that nearly every Haskell program uses (e.g. containers, text, bytestring, deepseq, etc.)
I think we should solve this problem outside of base.
Now, to answer the question Ben asked:
Have you considered using an alternative prelude in the past? Did you end up doing so? If not, why?
I do at the moment use
relude by Kowainik for application development and the occasional library that is so tightly coupled to me that I include it anyway (but would rather not, because of the deps footprint).
I initially did not use one because the ones that existed before were either abandonned or did not resonate with me, or wanted to much to tell me how to do things.
relude did check some of the boxes that had repelled me from alternative preludes at first, and that is why I am using it this day.
What kind of stability guarantees are we planning for such a base? I would assume that this would have the same long-term guarantee as base, but we should be explicit.
Yes, I would expect this library would have similar stability characteristics to
base. If we had a better story for preserving compatibility while evolving typeclass hierarchies then it may be possible for such a library to have even stronger guarantees than
base since we could in principle maintain could retain compatibility with a wide range of GHC releases.
The tricky part here is that
base (unfortunately) currently serves a few, largely orthogonal roles:
- it serves as the home of GHC’s IO subsystem (the event manager) which is closely tied to GHC’s runtime system (e.g.
- it serves as the home of several core typeclasses which are closely tied to the compiler (e.g.
- it serves as the home for wrappers to GHC primops which could in principle be implemented elsewhere (e.g.
- it serves as a “dumping ground” for things that are “foundational” enough that they should be shipped with the compiler, but which otherwise have no particular relation to GHC (e.g.
In my mind,
base really ought to be several different packages. This is even something that has been attempted in the past. However, implementation is sadly non-trivial as due to, among other things, module cycles and orphan instance issues.
base would be a way forward here, agreed. We’d have to figure out what such a freeze would look like. One thing I can imagine we’d want to get in before freezing is the
Profunctor work and a few changes to
Bifunctor. As far as big ticket items, we don’t have any that I’m aware of.
I really agree with Hecate here. Honestly I don’t want much out of Prelude - I want a fast String type and not having to use OverloadedStrings (omg my phone just auto completed this??), I want partial functions to not be exported by default, I want common functions such as
for exported, and i want functions like foldl fixed.
Basically - I want the defaults for beginners and hobbists be safe to use.
Large projects will inevitably develop their own bigger Prelude which is relevant for their applications. This is not a problem imo.
I have two concerns with alternative preludes and alternatives to base, and they are both I think more social problems than technical ones, and solvable, but something that I think needs to be addressed mindfully.
The first problem is that, when prelude and base are the default, bringing in alternatives can make things much harder for anyone new to a codebase, and especially new to haskell itself. When every project is using the same set of common names for things that are defined with perhaps subtle differences across many different preludes, there becomes a lot of unlearning and relearning as you jump from one codebase to another. Even having a single blessed alternative still means that for every project you have to orient yourself depending on whether you are using base or base’, prelude or prelude’.
The second problem is possible dependency bloat. If there’s a single pretty widely used base’ and prelude’, and it largely just collects dependencies everyone is using already, then it might not be such a huge deal, but as you start to have competing bases and preludes gain popularity then you need to pull them, and all of their transitive dependencies in, as your program grows larger, and for modestly sized programs there is a good chance you’ll end up having all of them as dependencies.
None of these points are to say that I think this isn’t a good idea, but they are a big part of my choice to not use alternative preludes in my own personal projects, and they’re worth considering I think as we have further discussion.
When every project is using the same set of common names for things that are defined with perhaps subtle differences across many different preludes, there becomes a lot of unlearning and relearning as you jump from one codebase to another.
This is to some extent true; however, it isn’t necessarily the case that names need to change under a
base'. In principle modules could be re-exported or shadowed in the new package to match those historically used by
base. Of course, the price one pays here is potentially confusing error messages (since, e.g.,
Data.List.head would not exist).
However, if the goal is to mostly reexport existing libraries whole-sale and perhaps hide a dubious few functions then this may be an acceptable tradeoff.
The second problem is possible dependency bloat. …
Quite right. This is why I think it would be best if alternative preludes nearly exclusively consisted of re-exports of things provided by other packages. This way the user is never forced to import such a package; it’s merely a convenient collection of things defined elsewhere.
I’d love a blessed alternative prelude which re-exports the things which are not included with
Prelude that we import all the time and have a low risk of causing name conflicts. I have similar reasoning to Rebecca Skinner for not currently using an alternative prelude. Being able to move code (and myself) around safely between modules and projects without drastic context shifts is extremely important to me.
I tried to use
papa before for this and it was great except that it didn’t include
error, which breaks my workflow (insert XKCD comic here)
papa doesn’t look like it’s maintained now though, unfortunately.
In particular, I’d like access to:
Just to name a few.
Control.Exception.evaluate are so important for using nonstrict evaluation, perhaps making them more available would help people in this area. Maybe it would also be nice to have
Not sure about partial functions. Partial functions are included with lots of libraries, from
lens, and I think on balance they usually make our code better.
foldl I’m similarly unsure about. Perhaps we can skirt around this by ensuring
foldl' is accessible from this hypothetical prelude?
not having to use OverloadedStrings (omg my phone just auto completed this??)
Just wait until you’re typing “you shouldn’t un…” and it autocompletes with
Suggestion: freeze “base” and call the new prelude by a new name. Eventually, just let “base” wither away.
On-topic: I see that chessai has the package name
std reserved and seemingly unused on Hackage (see here).
I think rather than basing off of
base the name of any alternative Prelude (e.g.
base-pure or something) that necessitates new users being aware of the original
base, that a clean start with something like
import Std) could be had with less baggage and then progressively adopted over time.
My main concern here is a “blessed” alternate prelude won’t go far enough in addressing historical baggage and so even with this blessing it will just become an example of the “There are now 15 competing standards” xkcd comic (with
Prelude still being what people default to far into the future).
I’d like for a future where if I pull in one of the current application development libraries & prelude alternatives, that I’d really now just be pulling in that particular framework’s opinionated app dev-oriented types and functions (e.g. a custom monad, logging, and re-exports of process context handling, probably unliftio, etc.). As most of the rest would be already provided by the HF’s new blessed prelude. And that “rest” is the type of stuff that tends to overlap among the excellent common prelude alternatives now like (but not limited to)
Anyway, thanks to everyone on the HF/HFWG for suggesting a change in this area
I like the idea. I personally use
Relude for this.
Not sure about having yet-another-alternate-prelude, instead of just replacing it with safer, and more performant standard library.
- Setting up alternate prelude introduces more friction on getting started. Be it a project or just experimenting Haskell. This is especially bad for people who want to get their feet wet with Haskell.
- Beginners have to deal with Cabal/Stack too early even if their main focus should be familiarizing themselves with Haskell. Getting started with Haskell is already daunting enough, and forcing them to deal with build tools this early might deter people away from Haskell. Makes it harder to suggest them using an alt prelude with less gotchas.
- More overhead because now people have to be familiar with two or more preludes. Especially for those that just want a prelude with the aforementioned traits.
Some may argue that it is simpler, like with
String. But I’m not sure how I feel about that if it’s at the expense for more headache in the near future. Like oh actually
String is a linked list so common string operations aren’t performant at all.
Just some opinions from my limited experience.
As with any common infrastructure, opinions are abound about what is wrong with it.
base has plenty of historic baggage, yet many issues have been addressed. Applicative Monad, FTP, Semigroup Monoid, Monad of No Return. I’ve shipped hundreds of thousands of lines of code to production through many transitions and GHC’s type system has made what would be harrowing in another language actually quite pleasant. The community is forgiving of change if the direction is an improvement. There are clear and well established issues with base (String, partial functions, etc). The problems are known. The community is encouraging of fixing them. Why create another standard when we can major version bump and rip off the band-aid?
I don’t use an alternative prelude, but if there were an “officially blessed” more comprehensive prelude, I would not hesitate to use it.
The single most important thing for me in a new prelude is to make import lists useful when reading a module. To me, that largely means they should summarize what important datatypes are used in a module. For instance, I would love to look at an import list and see, “this module uses the State monad, and
IntMaps, and these project local things.” Maybe the code also uses
second, but that’s not the most important thing to know about it: the most useful thing to see is that it works with
That’s what I like about Edmund’s list of modules – for the most part, they provide functions rather than datastructures, and give little to no info about the big picture contents of the module. On the other hand, I would not want all the monad transformers in Prelude, because they give important clues about how the functions in the module will operate.
Of course, that’s just what I think would make the import section most useful to me, so I’d be interested to hear what others think a useful import section looks like.
I think Haskell has to have a bloated Prelude, not necessarily abandoning the existing one. Both beginners and experienced haskellers should benefit from not having to deal with package lists and a ton of imports every time they want to do something basic. One technical concern I have is that Stack to this day doesn’t really support mixins (so as to have an implicit alternative Prelude module).
Incidentally, I really like the way IHP has multiple preludes for different parts of the project.. Maybe having a lot of preludes is the right way in general?
I noticed that my previous 1am comment didn’t explicitly answer the question:
I mostly use base. I’ve tried using relude a few times and while I think it has better defaults, I often found myself wanting more/other things when workingon different projects.
As my project grow I realized that my process for creating a new module is to copy the head of an existing module and change the module name. This is because often there is a set of common functions that I import and use throughout a project which are tedious to add by hand, and they may change from project to project.
For example, in some project I’d really want to have
throwError everywhere, for another project
modify from lens might be really common. For one project I might want a special trace function that uses pretty-simple, for another project maybe I want one that uses
Different projects have different defaults, so I often have a local Utils.hs that grows organically and which caters for that project. It makes more sense to me to be able to control what a project needs by default, and this has a few advantages in terms of ergonomics:
- Smaller import lists: makes it possible to focus on what’s actually unique for this module
- GHC emits a warning for unused imports, and it’s tedious to remove and add imports for stuff I use frequently
- Toolings aren’t as good for cross module stuff atm, but jump to definition locally works for me
- Everything is in one place
So this is why I believe this approach is better for non trivial projects. We can’t satisfy everyone, I myself even have different needs for different projects! What we can do is prevent people from shooting themselves in the foot and crash their systems, leak memory and ultimately share their bad experience with Haskell due to legacy defaults that most agree are problematic.
Just my two cents.
As an industry user who rolls our own IO solution based on libuv, we’d like to see a minimal base. The
Handle stuff in base feels like 90’s comparing to rust or golang’s buffered IO with utf8 default codec. The overall package structure change should make pushing progress easier rather than more difficult.
I would jump to a bigger, safer and more beautiful prelude at once. And I would most like it to be called
* * *
The good note that there are different classes of use cases has already been given and I think it is essential that we spell these classes out. The simplest is the dichotomy of libraries and applications — I am going to consider it presently. Another note to keep in mind is that the purpose of a prelude is twofold: to enable presence and to advertise absence.
If I am writing a pure library for munching big data:
There is really no point for me in having potentially useful data structures dispersed across many packages. I would rather have all of them at hand. Enable me to use the best tool for the job by default.
containerskind of does the right thing here, and it should be pushed farther.
At the same time, I would rather not have anything to do with IO, Template Haskell and
unsafeCoercein this library, and I would like to be enabled to advertise that. The more features I can advertise not having — the better.
If I am writing an application:
I may need streaming, concurrency, error handling, an effect system… Some of these are represented by many nearly indistinguishable choices. I would like to have a starter pack that makes the safest and the most approachable choice for me.
riois a kind of prelude that makes steps in this direction, choosing the effect system of
ReaderT IOfor you, among other things.
I would like to advertise the absence of unsafe functions.
For a bad example,
vectoris not something I would like to use since it makes no effort to provide a total interface. Or, for that matter,
For a good example,
protoludeexports only a single unsafe function
panicthat emits a warning upon being compiled — this means that a combination of
-Wall -Werroris a guarantee that only safe primitives are used.
This gets us to a category common to everyone: obsolete things that should go away.
base has too many of them.
- Why do we have
base, when there is
- Why do we have lazy IO in
base, when it is known to be problematic and there are many good alternatives, such as the conceptually simple
- Why do we have ports of C libraries in
base, such as
getOpt, when we have libraries that do the same in a type safe way?
- Why do we have unsafe functions like
basewhen pattern matching is the «killer feature» of Haskell?
The list goes on.
There should be a process for throwing obsolete things away, lest we drown. There is no hiding behind «blessed» alternative preludes from this. All of us need a
base that we can be proud of, that shows the best of Haskell.