2012-03-28 2 views
3

아래 코드는 구문 오류 메시지를보고합니다OCaml에서 서로 참조하는 두 가지 유형을 정의하는 방법은 무엇입니까?

type 'a edge = 
    |Empty 
    |End of 'a * 'a vertex * 'a vertex and 
type 'a vertex = 
    |Empty 
    |Vertex of 'a * 'a edge list;; 

어떻게 서로 참조하는 두 가지 유형을 정의하기 위해?

+1

이가 자주 묻는 질문입니다. 다음은 유사한 링크입니다. http://stackoverflow.com/questions/3026123/ocaml-forward-declaration –

+0

감사. 앞으로 선언문을 알지 못했습니다. – lkahtz

답변

6

두 번째 type 구문이 올바르지 않습니다 :

type 'a edge = 
    |Empty 
    |End of 'a * 'a vertex * 'a vertex 
and 'a vertex = 
    |Empty 
    |Vertex of 'a * 'a edge list;; 
+0

(상호 회귀 적 유형을 정의하려면 'and'키를 사용해야합니다.) –

관련 문제