的MonadTrans类型定义如下:为什么MonadTrans不是整个类型?
class MonadTrans t where
-- | Lift a computation from the argument monad
-- to the constructed monad.
lift :: (Monad m) => m a -> t m a
,看着执行:
instance MonadTrans (ExceptT e) where
lift = ExceptT . liftM Right
的ExceptT
类型构造有三种类型的变量:
newtype ExceptT e m a =
ExceptT { runExceptT :: m (Either e a)) }
所以类型构造函数ExceptT
未完全适用于类型。
为什么有可能,更不用说在的实例实现MonadTrans
中的所有类型变量?
Haskell类中的_kinds_类型变量是从类声明中如何使用这些变量推断出来的。在这里,'t ::(* - > *) - > * - > *'因为它需要一些'm'和'a',因为它是一个类型(和'm :: * - > *'因为它需要'a'来应用它,因为它是一种类型)。 – Alec