strict-base-types: Strict variants of the types provided in base.
It is common knowledge that lazy datastructures can lead to space-leaks. This problem is particularly prominent, when using lazy datastructures to store the state of a long-running application in memory. The easiest solution to this problem is to use fully strict types to store such state values. By "fully strict types" we mean types for whose values it holds that, if they are in weak-head normal form, then they are also in normal form. Intuitively, this means that values of fully strict types cannot contain unevaluated thunks.
To define a fully strict datatype, one typically uses the following recipe.
Make all fields of every constructor strict; i.e., add a bang to all fields.
Use only strict types for the fields of the constructors.
The second requirement is problematic as it rules out the use of
the standard Haskell
Either, and pair types. This library
solves this problem by providing strict variants of these types and their
corresponding standard support functions and type-class instances.
Note that this library does currently not provide fully strict lists.
They can be added if they are really required. However, in many cases one
probably wants to use unboxed or strict boxed vectors from the
library (http://hackage.haskell.org/package/vector) instead of strict
lists. Moreover, instead of
Strings one probably wants to use strict
Text values from the
This library comes with batteries included; i.e., missing instances
for type-classes from the
lens packages are included. Of particluar interest is the
type-class provided by the lens library
It is used in the following example to simplify the modification of
(-# LANGUAGE TemplateHaskell #-) -- replace with curly braces, (-# LANGUAGE OverloadedStrings #-) -- the Haddock prologues are a P.I.T.A! import Control.Lens ( (.=), Strict(strict), from, Iso', makeLenses) import Control.Monad.State.Strict (State) import qualified Data.Map as M import qualified Data.Maybe.Strict as S import qualified Data.Text as T -- | An example of a state record as it could be used in a (very minimal) -- role-playing game. data GameState = GameState ( _gsCooldown :: !(S.Maybe Int) , _gsHealth :: !Int ) -- replace with curly braces, *grmbl* makeLenses ''GameState -- The isomorphism, which converts a strict field to its lazy variant lazy :: Strict lazy strict => Iso' strict lazy lazy = from strict type Game = State GameState cast :: T.Text -> Game () cast spell = gsCooldown.lazy .= M.lookup spell spellDuration -- ... implement remainder of spell-casting ... where spellDuration = M.fromList [("fireball", 5)]
See http://www.haskellforall.com/2013/05/program-imperatively-using-haskell.html for a gentle introduction to lenses and state manipulation.
Note that this package uses the types provided by the
(http://hackage.haskell.org/package/strict), but organizes them a bit
differently. More precisely, the
only provides the fully strict variants of types from
is in-sync with the current base library (base-4.6),
provides the missing instances for (future) Haskell platform packages, and
conforms to the standard policy that strictness variants of an existing datatype are identified by suffixing 'Strict' or 'Lazy' in the module hierarchy.
|Versions [faq]||0.1, 0.2, 0.2.1, 0.2.2, 0.2.3, 0.3.0, 0.4.0, 0.5.0, 0.6.0, 0.6.1|
|Dependencies||aeson (>=0.6), base (>=4.5 && <5), bifunctors (>=3.0), binary (>=0.5), deepseq (>=1.3), ghc-prim, hashable (>=18.104.22.168), lens (>=3.9), QuickCheck (>=2), semigroups (>=0.18.3), strict (>=0.3.2 && <0.4) [details]|
|Copyright||(c) 2006-2008 by Roman Leshchinskiy (c) 2013-2014 by Simon Meier|
|Author||Roman Leshchinskiy <email@example.com>, Simon Meier <firstname.lastname@example.org>|
|Maintainer||Simon Meier <email@example.com>|
|Source repo||head: git clone https://github.com/meiersi/strict-base-types.git|
|Uploaded||by SimonMeier at Sun Feb 11 14:05:09 UTC 2018|
|Distributions||LTSHaskell:0.6.1, NixOS:0.6.1, Stackage:0.6.1|
|Downloads||5006 total (161 in the last 30 days)|
|Rating||(no votes yet) [estimated by rule of succession]|
Docs available [build log]
Last success reported on 2018-02-11 [all 1 reports]
For package maintainers and hackage trustees