Ocaml에서 React의 유형화 된 버전을 만들려고합니다. 더 기능적으로 만들기 위해 레코드를 렌더링 인수로 전달합니다. 컴파일러는 let newInstance = { props; state = nextState; updater = (mkUpdater props) }
에 updater = (mkUpdater props)
의 유형을 추론 할 수없는 이유 이해가 안Ocaml 유형 추정이 잘못되었습니다.
type ('props,'state) reactInstance =
{
props: 'props;
state: 'state;
updater: 'a . ('props,'state) reactInstance -> 'a -> 'state -> unit;}
and ('props,'state) reactClass =
{
getInitialState: unit -> 'state;
render: ('props,'state) reactInstance -> element;}
module type ComponentBluePrint =
sig
type props
type state
val getInitialState : unit -> state
val render : (props,state) reactInstance -> element
end
module type ReactClass =
sig
type props
type state
val mkUpdater :
props ->
((props,state) reactInstance -> 'e -> state) ->
(props,state) reactInstance -> 'e -> unit
val reactClass : (props,state) reactClass
end
module CreateComponent(M:ComponentBluePrint) =
(struct
include M
let rec mkUpdater props f i e =
let nextState = f i e in
let newInstance =
{ props; state = nextState; updater = (mkUpdater props) } in
()
let reactClass =
{ render = M.render; getInitialState = M.getInitialState }
end : (ReactClass with type props = M.props and type state = M.state))
한 가지입니다.
Error: Signature mismatch:
Values do not match:
let mkUpdater :
props =>
(reactInstance props state => '_a => '_b) =>
reactInstance props state => '_a => unit
is not included in
let mkUpdater :
props =>
(reactInstance props state => 'e => state) =>
reactInstance props state => 'e => unit
'_a와'e의 차이점은 무엇입니까? 정확히 똑같은 것처럼 보입니다. 이 유형을 확인하려면 어떻게해야합니까?
제공하신 오류는 귀하의 파일이 생성 한 실제 오류가 아닙니다. 올바른 오류는 "오류 :이 표현식은 ('a ->'b -> c) -> 'a ->'b -> 'd 이지만 표현식은 ('e, 'c) reactInstance -> 'f ->'c -> 단위 유형 'a ->'b -> 'c는 유형 ('e, 'c)과 호환되지 않습니다. reactInstance " – Drup
다음과 같은 여러 가지 오류가 있습니다. 파일이지만, 작업의 의미가 무엇인지 모른 채이를 해결하는 것은 어렵습니다. 첫 번째로 나에게로 건너 뛰는 것은 업데이터 필드에서''a''입니다. 여기에서 forall을 사용 하시겠습니까? 매우 유용하지는 않습니다. – Drup