Alternative preludesMiscellaneous
Lots of people dislike the standard prelude, for example for its use of String instead of Text. There have been several attempts to make better ones.
Recommendations
base-prelude or Prelude (the package, not the module) are almost unambiguously a net win because they simply reexports things from base and let you reduce your imports without making you learn anything new.
As for other preludes, it's hard to say.
- relude has the best documentation.
- protolude looks nice.
- classy-prelude is used more often than all other preludes (judging by Github's code search), which probably means something.
Anyway, it all depends on your coding style and what exactly you're writing.
If you're starting a huge project from scratch, you might want to look at foundation, which reinvents a lot of things (even Vector
and Text
), but claims to do it better.
-
Excellent documentation: Haddock with
doctest
-tested examples, tutorial, migration guide fromPrelude
. -
Beginner-friendly: doesn't require advanced Haskell knowledge to use it, but takes advantage of intermediate Haskell features to provide excellent performance and descriptive error messages.
-
Efficient strings: focuses on using functions with more efficient string types like
Text
orByteString
instead ofString
where appropriate. -
Opt in oriented: contains various extremely useful functions. But they are not exported by default to not spoil global namespace.
-
Custom HLint rules: has custom
hlint
rules that allow you to improve code quality after migration torelude
.
Used in:
See full list here: relude
's reverse dependencies
<notes are empty>
<notes are empty>
A prelude by Stephen Diehl. Described here by its author.
Reexports:
- base, mtl, deepseq, async, void, safe (safer functions for lists)
Text
/LText
,ByteString
/LByteString
,Map
,Set
- Some utility functions (
orAlt
,ordNub
,whenM
, etc) - Rewrites functions/classes that aren't present in earlier versions of base (
bool
,Bifunctor
, etc)
Other things:
- Defines a class for string conversion and generalises functions like
show
andprint
- Renames
id
toidentity
(because it's convenient to be able to name variablesid
) - Generalises
map
tofmap
, generaliseshead
toFoldable
protolude-lifted – a version with reexports from lifted-base and lifted-async for convenient work in monads other than IO
<notes are empty>
Not actually an alternative Prelude, but rather a convenient way to define your own Prelude. It re-exports all of base except for Prelude
.
GHC will implicitly import the module called Prelude
, which is usually found in the base
package. If, however, you depend on base-noprelude rather than base and your package has a module called Prelude
, that will be used instead, allowing you to customise it to your needs.
Designed to work out of the box with alternative Prelude
packages such as Prelude.
Could be combined with one of the actual alternative preludes with a dummy Prelude.hs
that uses the qualified module export technique, so that you don't have to import the alt-prelude in every module.
<notes are empty>
A “foundation” prelude by the author of classy-prelude. Exports two modules – CorePrelude
(intended for developers who want to make their own prelude), and BasicPrelude
(a simple prelude for users, built on CorePrelude
).
CorePrelude
reexports:
- commonly used functions from
Prelude
and other base modules - types (the usual bunch –
Map
,Vector
,HashMap
,ByteString
,Text
, etc) - a selection of functions from other packages (
lift
andliftIO
,</>
and<.>
, as well as hashing functions from hashable, functions for catching exceptions from lifted-base, andreadArgs
from ReadArgs, a very simple parser for command line arguments)
It also reimplements functions like putStrLn
and print
for Text
, and a small number of utility functions (bool
, equating
).
BasicPrelude
, additionally:
- reexports
Control.Monad
, methods ofFoldable
andTraversable
, some functions fromData.List
- generalises
++
,concat
, andmap
- replaces
read
,show
,readFile
, etc with theirText
-based equivalents
-
Doesn't export
&
. -
Focuses on
Text
, so can be annoying if you use many libraries that needString
. -
Only reimplements a few functions for compatibility with older versions of base (other preludes reimplement more).
-
Feels somewhat opinionated (why hashable and ReadArgs but not more commonly used libraries like deepseq or mtl? etc).
<notes are empty>
Foundation is a Haskell project to implement a modern & performant standard library with various centrally maintained functionalities.
Haskell's base has been designed a while ago and shows its age. For better or worse, it's also really hard to change base, leading to many interesting but ultimately fruitless discussions, lots of wasted efforts, and/or duplicated pieces and libraries.
Also many core libraries, which brings lots of welcome modern additions to the language (text, bytestring, vector, & many others), are maintained on the side, without coordination. For example bytestring and vector doesn't share any code.
Foundation is trying to provide a solution to those technical and maintainance limitations.
<notes are empty>
A single module reexporting most definitions in base. Doesn't serve any purpose other than reducing the number of imports, but is still pretty useful. (For me it routinely shaves off 5–10 imports.)
rebase – uses base-prelude and exports lots of additional modules
<notes are empty>
A pretty interesting prelude – it depends on lots of commonly used packages (containers, deepseq, hashable, mtl, text, time, uuid, vector, and more), and makes their modules available to you via the Rebase.*
namespace – so, for instance, instead of adding a dependency on text and importing Data.Text
you can just import Rebase.Data.Text
and get Data.Text
, Data.Text.IO
and Data.Text.Encoding
simultaneously. This means that you save some imports and don't have to manually add a dependency.
It also provides a Rebase.Prelude
module that reexports many non-conflicting functions and types from other modules (as well as a huge subset of base, by depending on base-prelude).
-
Exports modules in full, not just arbitary subsets.
-
Shaves off more dependency declarations than other libraries.
-
A superset of base-prelude.
<notes are empty>
This package provides a "Prelude" module drop-in replacement for base's Prelude
module.
Goals of this package include:
- Be reasonably modest and remain close in spirit to the
base
package's scope - Depend only on
base
(viabase-noprelude
) for recent GHC versions - Avoid partial functions being in scope by default; redefine common partial functions such as
read
orhead
to beMaybe
-valued - Provide a uniform "Prelude" across multiple GHC releases (currently GHC 7.0 and newer supported) to the extent possible given typeclass restructurings such as AMP or FTP
- Reduce
import
clutter by reexporting common verbs from modules such asControl.Monad
andControl.Applicative
<notes are empty>
Yet another prelude by Michael Snoyman. From the README:
A Haskell prelude optimized for safety.
No partial functions, period.
Choose best in class libraries (bytestring, text, etc) and promote them.
Regardless of the versions of underlying libraries, this package will always export a consistent API, so that CPP usage should be constrained to just inside this package.
Use generalization (via type classes) when they are well established. For example:
Foldable
andTraversable
yes,MonoFoldable
no.Encourage qualified imports with a consistent naming scheme.
Export any non-conflicting and not-discouraged names from this module that make sense, e.g.
ByteString
,Text
, orreadIORef
.
<notes are empty>
<notes are empty>
-
Maintained by company which uses Haskell in production
-
Reexports a lot of things you usually need in your code (
containers
,transformers
,text
, etc.) -
Textual data type is defaulted to
Text
instead ofString
-
All standard
IO
functions are lifted toMonadIO
-
A lot of commonly used idioms and convenient functions are introduced
cardano-sl
uses universum
as a custom prelude.
<notes are empty>
<notes are empty>
From the README:
SubHask is a radical rewrite of the Haskell Prelude. The goal is to make numerical computing in Haskell fun and fast. The main idea is to use a type safe interface for programming in arbitrary subcategories of Hask. For example, the category Vect of linear functions is a subcategory of Hask, and SubHask exploits this fact to give a nice interface for linear algebra. To achieve this goal, almost every class hierarchy is redefined to be more general.
<notes are empty>
A prelude for applications. Doesn't try to fix anything in Haskell, just reexports lots and lots of packages in a single module (aeson, lens, data-default, and so on; as well as the usual ones like bytestring, text, unordered-containers, etc).
<notes are empty>
<notes are empty>
<notes are empty>