【发布时间】:2016-11-19 03:02:39
【问题描述】:
我想用 Clean(一种与 Haskell 非常相似的语言)解决这个问题:
有一个class Node t,有两个实例:instance Node EdgeList 和instance Node Adjacency。我想创建一个 Graph,它是一个数组或节点列表。
Graph的定义是:
class Graph t1 t2 | Node t2 where
resetGraph :: (t1 t2) -> (t1 t2)
graphSize :: (t1 t2) -> Int
...
我想编写实例。一个带数组,一个带列表。首先,我尝试使用列表,但出现错误:t2 not defined
instance Graph [t1] t2 | t2 t1 where
(resetGraph) :: [t1] -> [t1]
(resetGraph) x = []
...
例如这样调用它:resetGraph listAdj 其中 listAdj 是 Adjacency 节点的列表
如果我只写:instance Graph [tt] tt,则会收到此错误:Error: this type variable occurs more than once in an instance type。
【问题讨论】:
标签: functional-programming clean-language