2016-06-05 4 views
4

나는 그렇지 컴파일 가능한 C입니다어떻게 포함합니까?

module type T = sig 
    type t 
end 

module Make (TypeProvider : T) = struct 
    include TypeProvider 
    type d = Wrapped of t 
end 

module Test = struct 
    include Make (struct type t = ForWrap end) 
    let f = function | Wrapped ForWrap ->() 
end 

내가

module Test = struct 
    type t = ForWrap 
    type d = Wrapped of t 
    let f = function | Wrapped ForWrap ->() 
end 

좋아하지만 실시간으로 컴파일 후 테스트를 상상 송시.

module Test = struct 
    include Make (struct type t = ForWrap end) 
    let f = function | Wrapped ForWrap ->() 
           ^^^^^^^ 

Error: Unbound constructor ForWrap

end 

그리고 그 이유를 이해할 수 없다 : OCaml의 날을 말한다. 내 솔루션의 문제점은 무엇입니까?

module M = Make(struct type t = ForWrapp end) 

ocamlc -c -i xxx.ml 당신이 모듈의 서명을 보여줍니다 :

+0

펑터 응용 프로그램은 런타임 작업이므로 "include"를 순수한 구문 수준 대체로 처리 할 수 ​​없습니다 – objmagic

답변

6

는 이제 Make (struct type t = ForWrapp end)의 서명을 보자 생성자 ForWrapp이 결과 모듈에서 사용할 수없는 것을

module M : sig 
    type t 
    type d = Wrrapped of t 
end 

참고. 이것이 코드가 타입 체크를하지 않는 이유입니다.

왜 생성자가 없어 졌습니까? 이것은 functor Make의 인수 서명이 T이기 때문입니다. T은 추상 형식 인 t을 정의합니다. Make을 더 자세한 서명 (여기에서 struct type t = ForWrapp end)이있는 모듈에 적용하더라도 T으로 강요되며 생성자 정보가 손실됩니다.