I often find that I want to insert regular functions into a โboundโ sequence. As in this contrived example:
getLine >>= lift (map toUpper) >>= putStrLn
I need to define the lift function lift :: (a -> b) -> a -> mb to do this job. The problem is that I donโt know such a function, and Hoogle doesn't look either. I find it strange because it makes sense to me.
Now there are probably other ways to make this work, but I like the way the dotless code style allows me to scan the line in one go to figure out what is going on.
let lift fx = return (fx) in getLine >>= lift (map toUpper) >>= putStrLn
My question comes down to the following: will I miss something, or why there is no such function as an elevator. My experience at Haskell is still very limited, so I guess most people decide this differently. Can someone explain to me the idiomatic way to resolve this issue.
haskell
Magnus kronqvist
source share