Description
Specify that lifted values were forced to WHNF or NF.
Description
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