-
-%************************************************************************
-%* *
-\subsection[monad-WwLib]{Simple monad for worker/wrapper}
-%* *
-%************************************************************************
-
-In this monad, we thread a @UniqueSupply@, and we carry a
-@GlobalSwitch@-lookup function downwards.
-
-\begin{code}
-type WwM result
- = UniqSupply
- -> (GlobalSwitch -> Bool)
- -> result
-
-{-# INLINE thenWw #-}
-{-# INLINE returnWw #-}
-
-returnWw :: a -> WwM a
-thenWw :: WwM a -> (a -> WwM b) -> WwM b
-mapWw :: (a -> WwM b) -> [a] -> WwM [b]
-
-returnWw expr ns sw = expr
-
-thenWw m k us sw_chk
- = case splitUniqSupply us of { (s1, s2) ->
- case (m s1 sw_chk) of { m_res ->
- k m_res s2 sw_chk }}
-
-mapWw f [] = returnWw []
-mapWw f (x:xs)
- = f x `thenWw` \ x' ->
- mapWw f xs `thenWw` \ xs' ->
- returnWw (x':xs')
-\end{code}
-
-\begin{code}
-getUniqueWw :: WwM Unique
-uniqSMtoWwM :: UniqSM a -> WwM a
-
-getUniqueWw us sw_chk = getUnique us
-
-uniqSMtoWwM u_obj us sw_chk = u_obj us
-
-thenUsMaybe :: UniqSM (Maybe a) -> (a -> UniqSM (Maybe b)) -> UniqSM (Maybe b)
-thenUsMaybe m k
- = m `thenUs` \ result ->
- case result of
- Nothing -> returnUs Nothing
- Just x -> k x
-\end{code}