I have this snippet of a function:
mapM (\x -> do t' <- t; return $ strSwop "if0" ("if" ++ show x) t') [0..(n-1)]
With
strSwop :: String -> String -> String -> String
t :: IO String
It works as expected but I don’t like the IO construct withing the lambda.
How can it be written differently?
I come out of the monad just to be wrapped again next line. Feels ugly.
If I do it this way:
mapM (\x -> t >>= strSwop "if0" ("if" ++ show x) t) [0..(n-1)]
It complains (obviously) about the return signature of strSwop 🙁
strSwop is just a string replacement function.
Is there a way to correctly write this?
Thanks.
— EDIT —
Just figured it out …
Works out:
mapM (\x -> liftM (strSwop "if0" ("if" ++ show x)) t) [0..(n-1)]
I would suggest
liftMor<$>