-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Specify that lifted values were forced to WHNF or NF. -- -- Alternative to bang patterns using CBV functions and unlifted data -- types. Tag your values to maintain the invariant that they were -- forced. Avoid liveness leaks on long lived data structures. -- -- Main tutorial on the only module. Here is a taste of how it will look -- like. -- --
-- {-# Language QualifiedDo #-}
--
-- import qualified Data.Forced as DF
-- import Data.Forced hiding (pure, fmap, (\<*\>), return, (>>=), (>>))
-- import Data.Map.Lazy qualified as ML
--
-- noThunksForWHNF :: IO ()
-- noThunksForWHNF = do
-- -- map0 actually evaluated on here.
-- let map0 :: Demand (ML.Map Char (ForcedWHNF Int))
-- map0 = DF.do
-- v <- demandWHNF (const (2 + 2) 'a')
-- DF.pure $ ML.insert 'a' v ML.empty
--
-- map1 <- extractDemand map0
-- go (ML.lookup 'a' map1)
--
-- -- pattern matching for de-structuring, no construction allowed.
-- go :: ForcedWHNF Int -> IO ()
-- go (ForcedWHNF i) = print i
--
@package data-forced
@version 0.3.0.0
module Data.Forced
-- | Contains a value of type a that has been forced to
-- Weak Head Normal Form. Constructor not
-- exported (so no coerce).
data ForcedWHNF a
-- | The only way to extract the underlying value.
pattern ForcedWHNF :: forall a. a -> ForcedWHNF a
-- | Contains a value of type a that has been forced to
-- Normal Form. Constructor not exported (so no
-- coerce).
data ForcedNF a
-- | The only way to extract the underlying value.
pattern ForcedNF :: forall a. a -> ForcedNF a
-- | A strict identity monad of UnliftedType kind. To be used via
-- -XQualifiedDo.
data Demand (a :: LiftedType) :: UnliftedType
-- | This is a CBV function. Evaluates the argument to WHNF before
-- returning.
demandWHNF :: forall a. a -> Demand (ForcedWHNF a)
-- | This is a CBV function. Evaluates the argument to NF before returning.
demandNF :: forall a. NFData a => a -> Demand (ForcedNF a)
-- | We don't ship the constructor of Demand. The only way to
-- extract a Demand is to sequence to a know point on IO.
-- From the PoV of the rest of the program, the tagged values with
-- ForcedWHNF or ForcedNF will have been demanded.
extractDemand :: Demand a -> IO a
-- | fmap analogue for Demands which are of the
-- UnliftedType kind.
fmap :: (a -> b) -> Demand a -> Demand b
-- | Places no demand on the value. pure analogue for
-- Demands which are of the UnliftedType kind.
pure :: a -> Demand a
-- | <*> analogue for Demands which are of the
-- UnliftedType kind.
(<*>) :: Demand (a -> b) -> Demand a -> Demand b
-- | return analogue for Demands which are of the
-- UnliftedType kind. Same as pure.
return :: a -> Demand a
-- | >>= analogue for Demands which are of the
-- UnliftedType kind.
(>>=) :: Demand a -> (a -> Demand b) -> Demand b
-- | >> analogue for Demands which are of the
-- UnliftedType kind.
(>>) :: Demand a -> Demand b -> Demand b
instance GHC.Show.Show a => GHC.Show.Show (Data.Forced.ForcedNF a)
instance GHC.Show.Show a => GHC.Show.Show (Data.Forced.ForcedWHNF a)