14
我们如何证明the continuation monad没有有效的MonadFix
实例?为什么MonadFix的实例不能用于连续monad?
我们如何证明the continuation monad没有有效的MonadFix
实例?为什么MonadFix的实例不能用于连续monad?
实际上,这并不是说不能有一个MonadFix
实例,只是库的类型有点过于拘束。如果你在所有可能的r
小号定义ContT
,则不仅MonadFix
成为可能,但到Monad
所有实例需要什么底层函子:
newtype ContT m a = ContT { runContT :: forall r. (a -> m r) -> m r }
instance Functor (ContT m) where
fmap f (ContT k) = ContT (\kb -> k (kb . f))
instance Monad (ContT m) where
return a = ContT ($a)
join (ContT kk) = ContT (\ka -> kk (\(ContT k) -> k ka))
instance MonadFix m => MonadFix (ContT m) where
mfix f = ContT (\ka -> mfixing (\a -> runContT (f a) ka<&>(,a)))
where mfixing f = fst <$> mfix (\ ~(_,a) -> f a)
它看起来像你的类型实际上是更受限制的。有没有真正的情况下强迫参数'ContT'是多态的将阻止有用的实现?如果没有,这可能只是一个历史问题-ContT已经存在了很长一段时间,很可能在排名第二的类型之前是Haskell公认的部分。 – dfeuer 2014-09-15 05:14:58
多态参数'ContT'也被称为'Codensity'。它缺乏定义'callCC'的能力。 – 2014-09-15 07:59:34
这个答案解释了为什么你的'forall r。 (a - > m r) - > m r''ContT'不能有'callCC'。 http://stackoverflow.com/a/7180154/414413 – Cirdec 2014-09-17 03:04:07