[Haskell-cafe] Using 'lens' for "over"-like computation in Monad
nikoamia at gmail.com
Sat Aug 30 07:44:45 UTC 2014
I'm trying to wrap my head around 'lens' library. My current exercise is to
modify something using Lens in monad. Say,
("Hello", "World") & _1 `myOp` (\a -> putStrLn a >> return a)
in IO, where myOp would be of type:
myOp :: Monad m => Lens s t a b -> (a -> m b) -> s -> m t
Of course I can write it myself, using combination of "view" and "set":
myOp lens f v = f (view lens v) >>= flip (set lens) v
(have not checked this, but something like that should do), but is there a
more elegant way?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe