1
我試圖從運行該代碼:使用ghci 7.6.3
定義類型爲Monad的
{-# LANGUAGE LiberalTypeSynonyms, TypeSynonymInstances #-}
type C m a = (a -> Action m) -> Action m
data Action m = Atom (m (Action m)) | Fork (Action m) (Action m) | Stop
這原始形式
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.39.8039&rep=rep1&type=pdf
:
instance (Monad m) => Monad (C m) where
f >>= k = \c -> f (\a -> k a c)
return x = \c -> c x
給出了這樣的錯誤:
Type synonym `C' should have 2 arguments, but has been given 1
In the instance declaration for `Monad (C m)'
與附加參數嘗試:
instance (Monad m) => Monad (C m b) where
f >>= k = \c -> f (\a -> k a c)
return x = \c -> c x
顯示了這個錯誤:
Kind mis-match
The first argument of `Monad' should have kind `* -> *',
but `C m b' has kind `*'
In the instance declaration for `Monad (C m b)'
如何糾正這一定義嗎?謝謝
http://stackoverflow.com/questions/16273896/implementing-this-monad-type-in-haskell http://stackoverflow.com/questions/24881351/why-cant-you-totally- apply-a-type-synonym-that-has-arguments-using-an-other-t – gliptak
'C m'是'Cont(Action m)',所以你應該在這裏使用Cont(如果你想看看如何這是有效的,只是看Cont的來源)。 – user2407038