Copyright | © Yghor Kerscher 2016 |
---|---|
License | BSD-3 |
Maintainer | kerscher@acm.org |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
The Haskell Report specifies the Prelude with a minimal amount of definitions that are always available in scope for application writers. Due to its simplicity and frugality, multiple alternatives and support libraries were devised to improve upon it, including:
Preliminaries
is one of such alternatives and builds upon classy-prelude, with the following functionality out-of-the-box:
- Data manipulation — i.e. microlens
- Streaming
- Concurrency
- Parallelism
- Read-only, write-only and read-write environments — i.e. mtl
To use it, put the following in your .cabal
file, ignoring the “…” for omited parts:
… default-extensions: NoImplicitPrelude build-depends: preliminaries >= 0.1.6 < 1
And on each file, add import Preliminaries
.
You might also want to look at this project’s Cabal file to check on useful GHC extensions to enable alongside this change. In case something does not build or you find other unpleasant aspects of the library, please contact the maintainer.
- module Lens.Micro.Platform
- module Lens.Micro.Contra
- module Data.Conduit.Async
- module Data.Conduit.TQueue
- module Control.Monad.Par
- parFork :: Par () -> Par ()
- parNew :: Par (IVar a)
- parNewFull :: NFData a => a -> Par (IVar a)
- parGet :: IVar a -> Par a
- parPut :: NFData a => IVar a -> a -> Par ()
- parSpawn :: NFData a => Par a -> Par (IVar a)
- parParMap :: (Traversable t, NFData b, ParFuture iv p) => (a -> b) -> t a -> p (t b)
- module Control.Monad.Parallel
- module Control.Parallel
- module Control.Parallel.Strategies
- thru :: a -> Strategy a -> a
- module Control.Monad.Reader
- module Control.Monad.State.Lazy
- module Control.Monad.Writer.Lazy
- module System.Environment
- getEnvironmentMap :: IO (Map String String)
- module System.Exit
- module ClassyPrelude.Conduit
- module Data.Biapplicative
- module Data.Bifoldable
- module Data.Bitraversable
- module Data.MonoTraversable.Instances
- module Data.Default
- module Data.String.Conversions
- type ($) f x = f x
Data manipulation
Lenses provide unified and first-class means to access and modify data structures. Platform
, included here, provides a lightweight alternative to the much larger Lens
module, while remaining for the most part compatible.
Use this tutorial as an introduction, minding the slightly different module names.
module Lens.Micro.Platform
module Lens.Micro.Contra
Concurrency
Structure programs so that different threads are controlled independently. Whenever you need to have distinct functionality happening “at the same time”, you probably want to use the functionality here. The core Async
functionality is provided by ClassyPrelude
. Modules below provide helpers to execute things asynchronously in streaming Conduit
s and a transactional queue to transfer data between threads.
module Data.Conduit.Async
module Data.Conduit.TQueue
Parallelism
Using multiple available resources in a device to compute a result is what parallelism is about. Whenever you want to chop your data so that many cores calculate parts of it and bring about a result, you want what the imports here.
Par
provides fine-grained control, while Parallel
provides a simple interface to create Strategies
to parallelise execution. In general it's easier to start with Parallel
and switch to Par
when more control is needed.
Since the names used by both modules are similar, this module prefixes par
to all Par
functions that would conflict with Parallel
.
module Control.Monad.Par
module Control.Monad.Parallel
module Control.Parallel
module Control.Parallel.Strategies
Environments
If your programs end up repeatedly passing parameters around for configuration, state or logging, you will benefit from the monads below.
module Control.Monad.Reader
module Control.Monad.State.Lazy
module Control.Monad.Writer.Lazy
System interface
Terminate your programs with exitFailure
or exitSuccess
.
You should ensure any scarce resources that outlive program termination are freed with appropriate Safe
functions such as onException
, bracket
, bracket_
, finally
, withException
, bracketOnError
or bracketOnError_
.
module System.Environment
getEnvironmentMap :: IO (Map String String) Source #
Retrieves the current list of environment variables as a Map
of keys for variable names and values for current assignment of each variable.
This is a single action. If you need to keep this structure in sync with system environment, it's your responsibility to call it again. Consider either calling a specific variable with getEnv
when you need it, or keep this structure in a TVar
and refresh it manually.
module System.Exit
Re-exports
module ClassyPrelude.Conduit
module Data.Biapplicative
module Data.Bifoldable
module Data.Bitraversable
module Data.Default
module Data.String.Conversions