【发布时间】:2017-04-18 10:39:49
【问题描述】:
我已经定义了一个monad转换器UlffT如下。
我正在与Halogen 合作,但这不是Halogen 问题——我只是提供上下文。 UlffT 意在堆叠在Aff 上并在HalogenM 中使用。
newtype UlffT m a = UlffT ( ExceptT Error (ReaderT Env m) a )
unUlffT :: forall m. UlffT m ~> ExceptT Error (ReaderT Env m)
unUlffT (UlffT m) = m
derive newtype instance functorUlffT :: Functor m => Functor (UlffT m)
derive newtype instance applyUlffT :: Monad m => Apply (UlffT m)
derive newtype instance applicativeUlffT :: Monad m => Applicative (UlffT m)
derive newtype instance bindUlffT :: Monad m => Bind (UlffT m)
derive newtype instance monadUlffT :: Monad m => Monad (UlffT m)
instance monadTransUlffT
:: MonadTrans UlffT where
lift = UlffT <<< lift <<< lift
instance monadEffUlffT
:: MonadEff eff m
=> MonadEff eff (UlffT m) where
liftEff = lift <<< liftEff
instance monadAffUlffT
:: MonadAff eff m
=> MonadAff eff (UlffT m) where
liftAff = lift <<< liftAff
到这里为止一切都很好。现在我为MonadAsk 定义明显的实例如下。
instance monadAskUlffT
:: MonadAsk Env (UlffT m) where
ask = UlffT $ lift ask
我得到了错误
Type class instances for type synonyms are disallowed.
UlffT 不是类型同义词。我期待有关 m 的错误,例如我必须声明像Monad m => ... 或Monad (UlffT m) => ... 这样的约束。
我在派生MonadAsk-instance 时遇到同样的错误。
【问题讨论】:
-
这里涉及到的
Env类型是什么?也许这就是同义词? -
这是正确的答案
标签: typeclass monad-transformers purescript newtype type-synonyms