<div>Hi All,</div><div><br></div><div>Can anyone help me lift a function that takes a function, so it can be used in a Monad?</div><div><br></div><div>The function I am given looks like "((b -> b) -> a -> a)", and viewing the definition of liftM2, it's almost what I need:</div><div><br></div><div>liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r</div><div>liftM2 f m1 m2 = do</div><div>  x1 <- m1</div><div>  x2 <- m2</div><div>  return (f x1 x2)</div><div><br></div><div>but I get the error:</div><div><br></div><div><div><div>   Expected type: (m b -> m b) -> m a -> m a</div><div>      Actual type: m (b -> b) -> m a -> m a</div></div><div><br></div></div><div>which makes sense, as liftM2 just wraps my function arg, whereas the function itself needs to operate on monadic values. So I figure I need:</div><div><br></div><div><div>neededLift :: (Monad m) => ((b -> b) -> a -> a) -> (m b -> m b) -> m a -> m a</div></div><div><br></div><div>Despite a rough appreciation of how liftM2 works ("unpack" desired monadic versions of the args, apply the function, then return to put result back in the Monad), my mind keeps hazing over regarding the changes I need to make in this case. I've tried implementing neededLift by composing other functions, and also by manual Monad wrangling, but the intuitive leap remains elusive.</div><div><br></div><div>I posted the specific problem over at SO (<a href="http://stackoverflow.com/questions/34152747/how-can-i-lift-an-fclabels-lens-to-a-monad">http://stackoverflow.com/questions/34152747/how-can-i-lift-an-fclabels-lens-to-a-monad</a>), but I think the specifics may be clouding what is probably a straightforward problem.</div><div><br></div><div>Cheers,</div><div>Si</div><div><br></div>