【发布时间】:2015-12-05 03:05:02
【问题描述】:
我似乎错过了一些基本的东西。
当我尝试使用 sampleGraph 进行映射连接时,我收到此错误:
Main> map join sampleGraph
<interactive>:3:10:
Couldn't match expected type ‘[(Start, [End])]’
with actual type ‘Graph’
In the second argument of ‘map’, namely ‘sampleGraph’
In the expression: map join sampleGraph
这是代码
type Node = Integer
type Edge = (Node,Node)
type Start = Node
type End = Node
newtype Graph = Graph [(Start,[End])] deriving (Eq,Show)
join :: (Start, [End]) -> [Edge]
join (start, ends) = map (\ e -> if start < e then (start, e) else (e, start)) ends
sampleGraph = (Graph
[(5,[1,2,3]),
(7,[1,2]),
(1,[1,2]),
(2,[1,2])
])
【问题讨论】: