2009-09-30 4 views
6

와 함께 사용이 내 오류입니다 :OCaml의 오류 -이 표현은 X 형을 가지고 있지만 타입 X

가능성이 원인이 발생 될 수 있습니다 무엇
Error: This expression has type nfa but is here used with type nfa 

? 나는 emacs tuareg를 사용하고 파일을 하나씩 읽어 오는 중이다. 때로는 이런 일이 일어나고 그렇지 않은 경우도 있습니다.

+1

는이 오류를 생성하는 코드를 게시 할 수 있습니까? – 0xFF

답변

10

ocaml tutorial에 대한 설명이 있습니다. 새로운 정의로 유형 정의를 숨겼습니다.

type nfa = int 
let f (x: nfa) = x 

type nfa = int 
let g (x: nfa) = x 

이전 레벨을 다시 시작하면 이전 정의가 지워집니다.

0

업데이트 :

이후 일반적인 문제는 동일하지만 오류 메시지가 타입 정의에 숫자, 유형은 내부적으로 차이가 분명하게 추가 (2013년 9월 발표)를 OCaml의 4.01.0 . 최상위에서 old OCaml FAQ에서

전체 예 :

type counter = Counter of int;; (* define a type *) 
type counter = Counter of int 
# let x = Counter 1;;   (* use the new type *) 
val x : counter = Counter 1 
type counter = Counter of int;; (* redefine the type, use it *) 
type counter = Counter of int 
# let incr_counter c = match c with Counter x -> Counter (x + 1);; 
val incr_counter : counter -> counter = <fun> 
# incr_counter x;;    (* now mix old and new defs *) 
Error: This expression has type counter/1029 
     but an expression was expected of type counter/1032 
#