[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / compiler / utils / LiftMonad.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
3 %
4 \section[LiftMonad]{A lifting monad}
5
6 \begin{code}
7 #if defined(__GLASGOW_HASKELL__)
8 module LiftMonad where { bogusLiftMonadThing = True }
9
10 #else
11 module LiftMonad (
12         LiftM,  -- abstract
13         thenLft, returnLft, mapLft
14     ) where
15
16 infixr 9 `thenLft`
17
18 data LiftM a = MkLiftM a
19         -- Just add a bottom element under the domain
20 \end{code}
21
22 Notice that @thenLft@ is strict in its first argument.
23
24 \begin{code}
25 thenLft :: LiftM a -> (a -> b) -> b
26 (MkLiftM x) `thenLft` cont = cont x
27
28 returnLft :: a -> LiftM a
29 returnLft a = MkLiftM a
30
31 mapLft :: (a -> LiftM b) -> [a] -> LiftM [b]
32 mapLft f []      = returnLft []
33 mapLft f (x:xs)
34   = f x           `thenLft` \ x2 ->
35     mapLft f xs   `thenLft` \ xs2 ->
36     returnLft (x2 : xs2)
37
38 #endif
39 \end{code}