While looking through the transformers package, I found this monad transformer called IdentityT.
Although I understand how the Identity monad is used (e.g. State is just an alias for StateT Identity) and how monad transformers work in general, I have no idea how that relates to IdentityT.
Since it’s not in the MTL, I’m guessing it was added in there just for completeness and has no practical use. Is that correct?
Well the linked documentation does say
Though I’m not aware of any situations where this is actually the case. Theoretically if you have a function like
foo :: (MonadTrans t, Monad m) => t m a -> bfor some usefulb, then you might want to be able to “dumb it down” to essentiallym a -> bby usingt = IdentityT.But
IdentityTis toMonadTranswhatIdentityis toMonad. It is the “pass-through” transformer, asIdentityis the “pass-through” monad. Just check out the source; it’s rather simple.IdentityT SomeMonad ashould behave identically toSomeMonad a, the only difference being the presence of an extra newtype (which, of course, is removed at compile time)