-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | 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. -- --
-- (-# 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
--
-- -- pure f <*> pure x = pure (f x) -- must hold for all f ---- -- This law does not hold for the expected applicative functor instance -- of Maybe, as this instance does not satisfy pure f -- <*> pure _|_ = pure (f _|_) for f = const. module Data.Maybe.Strict -- | The type of strict optional values. data Maybe a :: * -> * Nothing :: Maybe a Just :: !a -> Maybe a -- | Given a default value, a function and a Maybe value, yields the -- default value if the Maybe value is Nothing and applies -- the function to the value stored in the Just otherwise. maybe :: b -> (a -> b) -> Maybe a -> b -- | Yields True iff the argument is of the form Just _. isJust :: Maybe a -> Bool -- | Yields True iff the argument is Nothing. isNothing :: Maybe a -> Bool -- | Extracts the element out of a Just and throws an error if the -- argument is Nothing. fromJust :: Maybe a -> a -- | Given a default value and a Maybe, yield the default value if -- the Maybe argument is Nothing and extract the value out -- of the Just otherwise. fromMaybe :: a -> Maybe a -> a -- | Analogous to listToMaybe in Data.Maybe. listToMaybe :: [a] -> Maybe a -- | Analogous to maybeToList in Data.Maybe. maybeToList :: Maybe a -> [a] -- | Analogous to catMaybes in Data.Maybe. catMaybes :: [Maybe a] -> [a] -- | Analogous to mapMaybe in Data.Maybe. mapMaybe :: (a -> Maybe b) -> [a] -> [b] -- | Analogous to _Just in Control.Lens.Prism _Just :: Prism (Maybe a) (Maybe b) a b -- | Analogous to _Nothing in Control.Lens.Prism _Nothing :: Prism' (Maybe a) () instance Generic (Maybe a) instance Typeable1 Maybe instance Data a => Data (Maybe a) instance Datatype D1Maybe instance Constructor C1_0Maybe instance Constructor C1_1Maybe instance Strict (Maybe a) (Maybe a) instance Arbitrary a => Arbitrary (Maybe a) instance FromJSON a => FromJSON (Maybe a) instance ToJSON a => ToJSON (Maybe a) instance Binary a => Binary (Maybe a) instance NFData a => NFData (Maybe a) instance Monoid a => Monoid (Maybe a) -- | The strict variant of the standard Haskell pairs and the corresponding -- variants of the functions from Data.Tuple. module Data.Tuple.Strict -- | The type of strict pairs. data Pair a b :: * -> * -> * (:!:) :: !a -> !b -> Pair a b -- | Extract the first component of a strict pair. fst :: Pair a b -> a -- | Extract the second component of a strict pair. snd :: Pair a b -> b -- | Curry a function on strict pairs. curry :: (Pair a b -> c) -> a -> b -> c -- | Convert a curried function to a function on strict pairs. uncurry :: (a -> b -> c) -> Pair a b -> c -- | Analagous to swap from Data.Tuple swap :: Pair a b -> Pair b a -- | Zip for strict pairs (defined with zipWith). zip :: [a] -> [b] -> [Pair a b] -- | Unzip for stict pairs into a (lazy) pair of lists. unzip :: [Pair a b] -> ([a], [b]) instance Generic (Pair a b) instance Typeable2 Pair instance (Data a, Data b) => Data (Pair a b) instance Datatype D1Pair instance Constructor C1_0Pair instance (Applicative f, a ~ a', b ~ b') => Each f (Pair a a') (Pair b b') a b instance Swapped Pair instance Field2 (Pair a b) (Pair a b') b b' instance Field1 (Pair a b) (Pair a' b) a a' instance Strict (a, b) (Pair a b) instance Bitraversable Pair instance Bifoldable Pair instance Bifunctor Pair instance (Arbitrary a, Arbitrary b) => Arbitrary (Pair a b) instance (FromJSON a, FromJSON b) => FromJSON (Pair a b) instance (ToJSON a, ToJSON b) => ToJSON (Pair a b) instance (Binary a, Binary b) => Binary (Pair a b) instance (NFData a, NFData b) => NFData (Pair a b) instance (Monoid a, Monoid b) => Monoid (Pair a b)