【问题标题】:"Type synonym instances are disallowed" even though I have a newtype monad transformer“不允许类型同义词实例”即使我有一个新类型的单子转换器
【发布时间】: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 =&gt; ...Monad (UlffT m) =&gt; ... 这样的约束。

我在派生MonadAsk-instance 时遇到同样的错误。

【问题讨论】:

  • 这里涉及到的Env类型是什么?也许这就是同义词?
  • 这是正确的答案

标签: typeclass monad-transformers purescript newtype type-synonyms


【解决方案1】:

gb 的评论:MonadAsk 当然有两个参数,第一个Env 是罪犯。

【讨论】:

    猜你喜欢
    • 2015-11-15
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多