我想使用以下代码尝试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中表达这种类型?
答案 0 :(得分:7)
这里有两个问题:
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