preliminaries-0.1.6.0: A larger alternative to the Prelude.

Copyright© Yghor Kerscher 2016
LicenseBSD-3
Maintainerkerscher@acm.org
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Preliminaries

Contents

Description

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.

Synopsis

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.

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 Conduits and a transactional queue to transfer data between threads.

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.

parFork :: Par () -> Par () Source #

parNewFull :: NFData a => a -> Par (IVar a) Source #

parGet :: IVar a -> Par a Source #

parPut :: NFData a => IVar a -> a -> Par () Source #

parSpawn :: NFData a => Par a -> Par (IVar a) Source #

parParMap :: (Traversable t, NFData b, ParFuture iv p) => (a -> b) -> t a -> p (t b) Source #

thru :: a -> Strategy a -> a Source #

A synonym for using.

Environments

If your programs end up repeatedly passing parameters around for configuration, state or logging, you will benefit from the monads below.

  • Reader provides a read-only environment, useful to ensure configuration invariants are kept.
  • State helps deal with scenarios where a variable is passed around many functions to “update” its state.
  • Writer provides a write-only environment, useful for logging and auditing purposes.

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

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.

Re-exports

Utilities

type ($) f x = f x Source #

This allows you to avoid parentheses in type declarations:

f :: h (g (f a b)) -> g (h (f a b))
f :: h $ g $ f a b -> g $ h $ f a b