I do not think there are libraries for this; conv
is an incredibly simple function, after all, and vice versa - it's just runListT
.
conv
is similar to liftMaybe
, often desired when using MaybeT
:
liftMaybe :: (Monad m) => Maybe a -> MaybeT ma liftMaybe = MaybeT . return
I would recommend calling it something on the liftList
lines. 1
Regarding the best monad transformer for non-determinism, I recommend taking a look at the logict package based on Oleg LogicT
, which is the logical logic of the back trace logic with some useful operations . As a bonus, since []
is an instance of MonadLogic
, these operations also work on lists.
1 Interestingly, we can define a function that generalizes the conv
and liftMaybe
:
import Data.Foldable (Foldable) import qualified Data.Foldable as F choose :: (Foldable t, MonadPlus m) => ta -> ma choose = F.foldr (\ab -> return a `mplus` b) mzero
This will probably make your code rather confusing, so I do not recommend using it :)
ehird source share