2015-12-28 2 views
2

У меня есть functorized графеСохраняя функтор в отдельном файле

module type GRAPH_LABELS = 
    sig 
     type label 
    end 

module type GRAPH = 
    sig 
     type label 
     type graph 
     val init : int -> graph 
     val size : graph -> int 
     val insert_directed_edge : graph -> int -> int -> label -> unit 
     val insert_edge : graph -> int -> int -> label -> unit 
     val neighbours : graph -> int -> (int*label) list 
    end 

module Graph = functor (L : GRAPH_LABELS) -> 
    struct 
     (* implementation which matches GRAPH *) 
    end 

Я хотел бы сохранить его в отдельном файле. Я положил все в graph.ml. Когда я создаю модуль из функтора

module VoidLabels = struct type label = unit end 
module Gr = Graph (VoidLabels) 

Я получаю сообщение об ошибке:

This module is not a functor; it has type 
     sig 
     module type GRAPH_LABELS = sig type label end 
     module type GRAPH = (* ... *) 

Как я должен сделать это правильно?

ответ

2

Я уверен, что у вас должно быть module Gr = Graph.Graph (VoidLabels).

+0

И как мне изменить исходный код, чтобы сделать мои звонки законными? – marmistrz

+2

Добавьте 'open Graph' в начало файла. Вы не можете использовать функтор как имя верхнего уровня, так что другого пути нет. – Drup

Смежные вопросы