하나의 모듈에서 다른 모듈을 사용하려고하는데 문제가 있습니다. 그러나 서명 불일치가 있다고 말하는 오류가 발생하며 이유가 확실하지 않습니다. . 나는이 일을 제대로하고 있다고 확신했다. 여기에 몇 가지 코드입니다 : 그래서 힙 단지 힙에 간단한 작업을 할 수 있지만, 어떤 이유로 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
사전에 감사!
'모듈 타입 HEAP = 펑터 (힙 : 힙) -> ...'는 모듈 타입 오류가 될 수 있습니다. 힙의 실제 정의를 제공 할 수 있습니까? – octachron
@ 옥타 크론이 추가되었습니다. 'functor (Heap : HEAP) ->'를 제거했지만 이제는 다른 서명 불일치가 생깁니다. – awallace04
어느 쪽이 좋습니까? 당신의 코드 예제는'functor (HEAP : HEAD) -> ...'가 제거 된 후에 작동합니다. – octachron