I am currently writing a project where I make a heavy use of ListT
monad transformer. When using plain lists, implementing nondeterminism is very easy. However once I had to convert my code to ListT
, it got much more complicated 1.
As a simple example: converting from [a]
to ListT a
actually requires composing two functions:
conv :: (Monad m) => [a] -> ListT m a
conv = ListT . return
Though it's simple, I am surprised it's not already there.
Questions:
- Is there some better way to handle nondeterminism where a monad transformer is needed?
- Are there any techniques / libraries for converting cleanly back and forth between lists and
ListT
?
1 The exact reasons are quite complicated, so I don't really want to elaborate too much on that.