2010-11-26 170 views
1

semiring模塊中元素的類型是ElementS,它是一組元素。當我定義零= ElementS.empty它說,有類型錯誤作爲類型元素<> ElementS.t簽名不匹配

我找不到任何類似的問題,並沒有能夠解決這個問題。

(*semiring.ml*) 
module type SEMIRING = 
sig 
    type elements 
    type poly = elements polynomial 
     type variable = int 

    (** Constants **) 
    val zero : elements (** Identity for + **) 
..... 
end 
    module CountingSemiring : SEMIRING = 
    struct 

module Ord : Carrier.Order = 
struct 
     let vector_order= 2 
end 

module Z = Carrier.Make(Ord) 

module ElementS = Set.Make( 
    struct 
    let compare = Pervasives.compare 
    type t = Z 
    end) 

    type elements = ElementS 
    type varmap = elements IntMap.t 
    type poly = elements polynomial 

    let zero = ElementS.empty 
end 

(* carrier.ml *) 
module Make (Ord:Order) = 
struct 
let o = Ord.vector_order 

type t = Elementi.t array 

    let gen i = 
    if(i < o) then 
    let arr = Array.make o (Elementi.N 0) in 
    Array.set arr i (Elementi.N 1) 
    else 
    failwith "Out of bound generate" 
.... 
end 
ERROR: Signature mismatch SEMIRING vs CountingSemiring 
     Values do not match: 
     val zero : ElementS.t 
     is not included in 
     val zero : elements 
when they should be the same. 
+0

一組S和S.empty有不同的類型。在本案中繞過這個約束的方法是什麼? – 2010-11-26 03:44:31

回答

2
type elements = ElementS 

這可能是一個錯字:你定義元素是一筆類型與一個恆定的構造ElementS

編譯器告訴你這種類型與ElementS.t不兼容。所以你應該寫:

type elements = ElementS.t