What is the difference between these three monad transformers?
1 Answer
Well, first of all ListT is not a true monad transformer. It disobeys the associativity law for certain underlying monads. It is also pretty slow, as is the monadic interface to lists in general. It is built on actual lists internally.
LogicT is probably the best choice for list-like monad transformers. It not only implements a proper monad transformer, but also some very useful combinators for fair list products.
ChoiceT is my own work. It is basically just a CPSed version of LogicT and is inspired by both LogicT and the ChoiceT from monadLib. It's very fast, often outperforming (non-transformed) lists, but the types may be scary and you are bound to the result type, which may be in your way sometimes.
Conclusion: If you're serious, use LogicT.
3 Comments
LogicT and ChoiceT encode lists as folds of some sort anyway, and as usual the "run" functions just unwrap that. Folds are already similar to a CPS'd list, and ChoiceT adds an extra layer of proper CPS on top of that, which is why it has a type signature only a mother could love. ;]
MonadTransinstance for these types, or their behavior in general?