我在下面的代碼中有類型問題(一些簡單的模塊函數圖實現)。看起來類型正在過着自己的生活。模塊:仿函數中的類型問題
我在模塊Edge中實現了type t = NotaEdge | Edge of int*v*v
,此模塊中的Graph類變爲type edge = E.t
。一切似乎對我來說都很好,除了事實上我無法模式匹配它,導致構造函數邊緣仍然未定義在模塊Graph中。
究竟在功能SUC當我試圖以配合邊緣(L,N,M):#錯誤:未綁定構造邊緣
希望有人能夠提前很好地呈現它,THX :)
module Vertex : Vertex with type label = int =
struct
type t = NotaNode | Node of int
type label = int
exception No of string
...
module Edge : Edge with type label = int and type v = Vertex.t =
struct
type v = Vertex.t
type t = NotaEdge | Edge of int*v*v
type label = int
exception No of string
...
module Graph (E : Edge) (V : Vertex) : Graph with type vertex = V.t and type edge = E.t =
struct
type vertex = V.t
type edge = E.t
type t = E.t list* V.t list
let empty = ([],[])
let rec suc (x:edge list) (v1:vertex) =
match x with
y::ys -> (match y with
(*Error-->*) Edge(l,n,m) -> if n == v1 then m::(suc ys v1) else suc ys v1
| _ -> [])
|[] -> []
let succ (t1:t) (v1:vertex) =
match t1 with
(x,_) -> suc x v1
...
類型t是抽象的(對不起,我沒有發佈簽名),我還沒有找到任何方法來做我想要做的與抽象,所以你建議它工作得很好,當我重新輸入任何地方的確切類型也許不是很優雅,但作品)。我很快就會關閉主題(也許到那時我們會得到一些有趣的東西) – mechu 2011-05-17 15:26:34
使用套筒扳手敲擊指甲沒有任何優雅之處,但它是當你想擰緊一些螺栓。 – nlucaroni 2011-05-17 15:31:25