-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstrict-base-types.cabal
145 lines (137 loc) · 5.56 KB
/
strict-base-types.cabal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
Name: strict-base-types
Version: 0.6.1
Synopsis: Strict variants of the types provided in base.
Category: Data
Description:
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.
.
1. Make all fields of every constructor strict; i.e., add a bang to
all fields.
.
2. 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 'Maybe', '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 'vector'
library (<http://hackage.haskell.org/package/vector>) instead of strict
lists. Moreover, instead of @String@s one probably wants to use strict
@Text@ values from the @text@ library
(<http://hackage.haskell.org/package/text>).
.
This library comes with batteries included; i.e., missing instances
for type-classes from the @deepseq@, @binary@, @aeson@, @QuickCheck@, and
@lens@ packages are included. Of particluar interest is the @Strict@
type-class provided by the lens library
(<http://hackage.haskell.org/packages/archive/lens/3.9.0.2/doc/html/Control-Lens-Iso.html#t:Strict>).
It is used in the following example to simplify the modification of
strict fields.
.
> (-# 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 'strict' package
(<http://hackage.haskell.org/package/strict>), but organizes them a bit
differently. More precisely, the @strict-base-types@ package
.
- only provides the fully strict variants of types from 'base',
.
- 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.
License: BSD3
License-File: LICENSE
Author: Roman Leshchinskiy <[email protected]>,
Simon Meier <[email protected]>
Maintainer: Bas van Dijk <[email protected]>, Oleg Grenrus <[email protected]>, Simon Meier <[email protected]>
Copyright: (c) 2006-2008 by Roman Leshchinskiy
(c) 2013-2014 by Simon Meier
Homepage: https://github.com/meiersi/strict-base-types
Cabal-Version: >= 1.6
Build-type: Simple
Tested-with:
GHC==7.4.2,
GHC==7.6.3,
GHC==7.8.4,
GHC==7.10.3,
GHC==8.0.2,
GHC==8.2.2,
GHC==8.4.4,
GHC==8.6.5,
GHC==8.8.1
extra-source-files:
CHANGES
source-repository head
type: git
location: https://github.com/meiersi/strict-base-types.git
library
ghc-options: -Wall -fwarn-incomplete-uni-patterns
if impl(ghc >= 8.0)
ghc-options: -Wcompat -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances
build-depends:
base >= 4.5 && < 5
, lens >= 3.9
, QuickCheck >= 2
, aeson >= 0.6
, binary >= 0.5
, deepseq >= 1.3
, hashable >= 1.1.1.0
, strict >= 0.3.2 && <0.4
, bifunctors >= 3.0
, ghc-prim
if !impl(ghc >= 8.0)
build-depends: semigroups >= 0.18.3
hs-source-dirs: src
exposed-modules:
Data.Tuple.Strict
Data.Maybe.Strict
Data.Either.Strict