我编写了一些简单的haskell 函数来计算图中给定顶点的邻居(见下文)。它编译得很好,但是,当我运行时adj g 1
,我收到以下错误:Couldn't match expected type `Int' against inferred type `Integer'
编码:
module Test where
import Prelude
import Data.List
type Node = Int
type Edge = (Int, Int)
type Graph = ([Node], [Edge])
g = ([1,2,3,4,5,6], [(1,2),(2,3),(2,4),(5,6)])
adj :: Graph -> Node -> [Node]
adj (vs, []) n = []
adj (vs,((s,e):es)) n | s==n = e:rec
| e==n = s:rec
| otherwise = rec
where
rec = adj (vs,es) n