Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding `kind` of MonadTrans

Tags:

haskell

Looking at the kind of Monad:

ghci>:k Monad
Monad :: (* -> *) -> Constraint

I believe that's because it takes an a from m a, and returns the Monad constraint.

Looking at MonadTrans's *kind, I see:

ghci>:i MonadTrans
class MonadTrans (t :: (* -> *) -> * -> *) where
  lift :: Monad m => m a -> t m a
        -- Defined in `Control.Monad.Trans.Class'
instance MonadTrans MaybeT
  -- Defined in `Control.Monad.Trans.Maybe'

So, the first (* -> *) comes from Monad's kind, I believe. But what about the * -> *?

like image 814
Kevin Meredith Avatar asked Nov 29 '25 01:11

Kevin Meredith


1 Answers

The second * -> * also comes from Monad's kind! A monad transformer takes a type argument that is a Monad (or at least a type that has the kind of a Monad) and produces a new type which is a Monad (which also has the kind of a Monad).

 * -> *            -- a Monad
(* -> *) -> * -> * -- Something that takes a Monad and makes a new Monad.
            * -> * -- also a Monad
like image 174
Cirdec Avatar answered Nov 30 '25 15:11

Cirdec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!