\section[Demand]{@Demand@: the amount of demand on a value}
\begin{code}
-{-# OPTIONS -w #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and fix
--- any warnings in the module. See
--- http://hackage.haskell.org/trac/ghc/wiki/CodingStyle#Warnings
--- for details
-
#ifndef OLD_STRICTNESS
module Demand () where
#else
type MaybeAbsent = Bool -- True <=> not even used
-- versions that don't worry about Absence:
+wwLazy, wwStrict, wwPrim, wwEnum :: Demand
+wwUnpack :: [Demand] -> Demand
+
wwLazy = WwLazy False
wwStrict = WwStrict
wwUnpack xs = WwUnpack False xs
seqDemand :: Demand -> ()
seqDemand (WwLazy a) = a `seq` ()
seqDemand (WwUnpack b ds) = b `seq` seqDemands ds
-seqDemand other = ()
+seqDemand _ = ()
+seqDemands :: [Demand] -> ()
seqDemands [] = ()
seqDemands (d:ds) = seqDemand d `seq` seqDemands ds
\end{code}
isPrim :: Demand -> Bool
isPrim WwPrim = True
-isPrim other = False
+isPrim _ = False
\end{code}
\begin{code}
+pprDemands :: [Demand] -> Bool -> SDoc
pprDemands demands bot = hcat (map pprDemand demands) <> pp_bot
where
pp_bot | bot = ptext SLIT("B")
| otherwise = empty
+pprDemand :: Demand -> SDoc
pprDemand (WwLazy False) = char 'L'
pprDemand (WwLazy True) = char 'A'
pprDemand WwStrict = char 'S'
seqStrictnessInfo :: StrictnessInfo -> ()
seqStrictnessInfo (StrictnessInfo ds b) = b `seq` seqDemands ds
-seqStrictnessInfo other = ()
+seqStrictnessInfo _ = ()
\end{code}
\begin{code}
| otherwise = StrictnessInfo xs is_bot
where
totally_boring (WwLazy False) = True
- totally_boring other = False
+ totally_boring _ = False
+noStrictnessInfo :: StrictnessInfo
noStrictnessInfo = NoStrictnessInfo
+isBottomingStrictness :: StrictnessInfo -> Bool
isBottomingStrictness (StrictnessInfo _ bot) = bot
isBottomingStrictness NoStrictnessInfo = False
-- appIsBottom returns true if an application to n args would diverge
+appIsBottom :: StrictnessInfo -> Int -> Bool
appIsBottom (StrictnessInfo ds bot) n = bot && (listLengthCmp ds n /=GT) -- not more than 'n' elts in 'ds'.
-appIsBottom NoStrictnessInfo n = False
+appIsBottom NoStrictnessInfo _ = False
+ppStrictnessInfo :: StrictnessInfo -> SDoc
ppStrictnessInfo NoStrictnessInfo = empty
ppStrictnessInfo (StrictnessInfo wrapper_args bot) = hsep [pprDemands wrapper_args bot]
\end{code}