我正在尝试运行以下代码:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.39.8039&rep=rep1&type=pdf
运用 ghci 7.6.3
{-# 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
Run Code Online (Sandbox Code Playgroud)
这个原始形式:
instance (Monad m) => Monad (C m) where
f >>= k = \c -> f (\a -> k a c)
return x = \c -> c x
Run Code Online (Sandbox Code Playgroud)
给出了这个错误:
Type synonym `C' should have 2 arguments, but has been given 1
In the instance declaration for `Monad (C m)'
Run Code Online (Sandbox Code Playgroud)
尝试使用附加参数:
instance (Monad m) => Monad (C m b) where
f >>= k = \c -> f (\a -> k a c)
return x = \c -> c x
Run Code Online (Sandbox Code Playgroud)
显示此错误:
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)'
Run Code Online (Sandbox Code Playgroud)
如何纠正这个定义?谢谢
部分应用的类型同义词不能是类型类实例,在这种情况下避免这种情况的唯一方法是使其成为数据或新类型声明.
您将不得不更改C的定义以使其工作为例如
newtype C m a = C ((a -> Action m) -> Action m)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
274 次 |
| 最近记录: |