summaryrefslogtreecommitdiff
path: root/compiler/utils/Util.lhs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/utils/Util.lhs')
-rw-r--r--compiler/utils/Util.lhs11
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/utils/Util.lhs b/compiler/utils/Util.lhs
index c5f1c0c2ed..ad678fd45d 100644
--- a/compiler/utils/Util.lhs
+++ b/compiler/utils/Util.lhs
@@ -32,6 +32,7 @@ module Util (
-- * Tuples
fstOf3, sndOf3, thirdOf3,
+ firstM, first3M,
-- * List operations controlled by another list
takeList, dropList, splitAtList, split,
@@ -104,7 +105,7 @@ import Data.List hiding (group)
import FastTypes
#endif
-import Control.Monad ( unless )
+import Control.Monad ( unless, liftM )
import System.IO.Error as IO ( isDoesNotExistError )
import System.Directory ( doesDirectoryExist, createDirectory,
getModificationTime )
@@ -210,6 +211,14 @@ sndOf3 (_,b,_) = b
thirdOf3 (_,_,c) = c
\end{code}
+\begin{code}
+firstM :: Monad m => (a -> m c) -> (a, b) -> m (c, b)
+firstM f (x, y) = liftM (\x' -> (x', y)) (f x)
+
+first3M :: Monad m => (a -> m d) -> (a, b, c) -> m (d, b, c)
+first3M f (x, y, z) = liftM (\x' -> (x', y, z)) (f x)
+\end{code}
+
%************************************************************************
%* *
\subsection[Utils-lists]{General list processing}