[Haskell-cafe] hoisting as well as lifting and returning
matthew.pocock at ncl.ac.uk
Sun Mar 23 14:56:00 EDT 2008
I've been using monad transformers for the first time in anger this week. They
certainly do the job. However, there's an operation that I keep defining over
and over again. It is sort of like lift and return in that it's glue to get
operations and values into the monad from outside it. Here are two examples.
hoistList :: (Monad m) => [a] -> ListT m a
hoistList = foldr (mplus . return) mzero
hoistMaybe :: (Monad m) => Maybe a -> MaybeT m a
hoistMaybe = maybe mzero return
The general idea is that you have some legacy, non-transform operation in some
monad MonadFoo, and you are writing an operation in MonadFooT. You want to
get the monadFoo value into MonadFooT. So, you say something like:
do vInMFT <- hoist vInMF
Is this a common enough operation on a monad transformer and it's 'raw' monad
to warrant a class of its own? I have 'hoist' methods for several monad
transformers, including RamdomMonadT, although I've probably defined them in
ways that are overly eager or eat stack/heap, so I'd prefer knowledgable
people to write them :)
There must be other operations that link the base monad with its transformed
version, other than 'hoist' - the runFooT method for example.
Perhaps 'hoist' already exists and I'm re-inventing the wheel?
More information about the Haskell-Cafe