循环类型同义词声明
我想用下面的代码尝试Haskell type
和data
type Program a = Maybe a -> (Operation a, Maybe Program a)
data Operation a = Read a | Write a
Program
遵循延续传球风格(CPS), Nothing
表示终止。 a
可以用Int
或其他东西实例化。
但是,GHC抱怨说:
main.hs:1:1:
Cycle in type synonym declarations:
main.hs:1:1-58: type Program a =
Maybe a -> (Operation a, Maybe Program a)
我是Haskell的新手,所以我不明白为什么这是不允许的。 我如何在Haskell中表达这种类型?
这里有两个问题:
Maybe (Program a)
,而不是Maybe Program a
工作版本将是:
newtype Program a = Program { runProgram :: Maybe a -> (Operation a, Maybe (Program a)) }
data Operation a = Read a | Write a
链接地址: http://www.djcxy.com/p/33151.html