2017-12-01 3 views
0

하나의 모듈에서 다른 모듈을 사용하려고하는데 문제가 있습니다. 그러나 서명 불일치가 있다고 말하는 오류가 발생하며 이유가 확실하지 않습니다. . 나는이 일을 제대로하고 있다고 확신했다. 여기에 몇 가지 코드입니다 : 그래서 힙 단지 힙에 간단한 작업을 할 수 있지만, 어떤 이유로 OCaml의 힙에 대한 서명이 항목에 대한 기능을 포함하도록되어 있다고 생각 기능의 무리를 포함다른 모듈에서 모듈을 사용하려고 시도 할 때 서명이 일치하지 않습니다.

module type ITEM = 
sig 
    type item 
    val leq : item * item -> bool 
    val initial : item 
end 
module type HEAP = 
sig 
    type item 
    type tree 
    exception InitHeap 
    val depth : tree -> int 
    val initHeap : int -> tree 
    val insert : item * tree -> tree 
    val isHeap : tree -> bool 
    val maxHeap : tree -> item 
    val replace : item * tree -> item * tree 
    val size : tree -> int 
    val top : tree -> item 
end 

module Heap (Item: ITEM) : HEAP = 
struct 
       type item = Item.item 

    let leq(p, q) : bool = Item.leq(p,q) 

    let max(p,q) = if leq(p,q) then q else p 
    and min(p,q) = if leq(p,q) then p else q 

    let intmax((p : int),q) = if p <= q then q else p 

    type tree = 
     | L of item 
     | N of item * tree * tree 

    exception InitHeap 

    let rec initHeap n = 
     if (n < 1) then raise InitHeap 
     else if n = 1 then L Item.initial 
      else let t = initHeap(n - 1) 
       in N (Item.initial, t, t) 

    let rec top t = 
     match t with 
     | (L i) -> i 
     | N (i,_,_) -> i 


    let rec isHeap t = 
     match t with 
     | (L _) -> true 
     | (N(i,l,r)) -> 
     leq(i,top l) && leq(i,top r) && isHeap l && isHeap r 

    let rec depth t = 
     match t with 
     | (L _) -> 1 
     | N(i,l,r) -> 1 + intmax(depth l,depth r) 

    let rec replace (i,h) = (top h, insert(i,h)) 
    and insert (i, h) = 
    match h with 
    | L _ -> L i 
    | N (_,l,r) -> 
     if leq(i,min(top l,top r)) 
     then N(i,l,r) 
     else if leq((top l),(top r)) 
      then N(top l,insert(i,l),r) 
      else N(top r,l,insert(i,r)) 

    let rec size h = 
    match h with 
    | L _ -> 1 
    | N (_,l,r) -> 1 + size l + size r 

    let rec maxHeap h = 
    match h with 
    | (L i) -> i 
    | N (_,l,r) -> max(maxHeap l, maxHeap r) 
end 

,하지만 난 그냥 원하는 HEAP 에 내가 오류를 ITEM 기능을 당겨 : 어떤 도움

Error: Signature mismatch: 
    Modules do not match: 
    sig val leq : int * int -> bool end 
    is not included in 
    ITEM 
    The value `initial' is required but not provided 
    File "lab13.ml", line 28, characters 8-26: Expected declaration 
    The type `item' is required but not provided 
    File "lab13.ml", line 26, characters 8-17: Expected declaration 

사전에 감사!

+0

'모듈 타입 HEAP = 펑터 (힙 : 힙) -> ...'는 모듈 타입 오류가 될 수 있습니다. 힙의 실제 정의를 제공 할 수 있습니까? – octachron

+0

@ 옥타 크론이 추가되었습니다. 'functor (Heap : HEAP) ->'를 제거했지만 이제는 다른 서명 불일치가 생깁니다. – awallace04

+0

어느 쪽이 좋습니까? 당신의 코드 예제는'functor (HEAP : HEAD) -> ...'가 제거 된 후에 작동합니다. – octachron

답변

1

당신은 아마 당신이

module type HEAD = sig … end 

functor(HEAD:ITEM) -> … 추가 의미

(recursely 유형의 오류가있는 HEAD 모듈 타입을 사용하지 module type HEAD = functor (Head:HEAD) -> sig … end)

module type HEAD = functor (Head:ITEM) -> sig … end 

을 썼다 부분은 HEAD의 서명 또는 펑터가됩니다. 따라서

module Heap (Item: ITEM) : HEAP 

은 즉

module Heap (Item: ITEM) : functor(Heap:HEAP) -> sig … end 

, 당신은 힙 고차 펑하게 추가 서명과 같은 일이다; 이는 구현의 경우가 아니다. 불행하게도, 펑터가있는 상태의 오류 메시지는 현재 부족하고,이 경우에는 형식 검사기가 오류를 자세히 설명하지 않습니다.

module type HEAD = sig … end 

같이 HEAD 모듈 유형을 재 작성하면,이 문제를 해결한다.

+0

불행히도 문제가 해결되지 않습니다. 당신이 말한 것은 비록 의미가 있습니다. 지금 가지고있는 오류를 나타 내기 위해 오류 메시지를 업데이트했습니다. 도와 주셔서 정말 감사합니다. – awallace04

+1

오류 메시지는 구체적인 항목 모듈이'initial' 값과'item' 유형에 대한 선언이 누락되어 ITEM 모듈 유형의 ​​유효한 구현이 아니라는 것을 알려줍니다. – octachron

관련 문제