私は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 タイプ 'a - >' b - > 'cはタイプ(' e、 'c)と互換性がありませんreactInstance " – Drup
エラーのように見える複数のものがあります。あなたの操作の意味論が何であるかを知らなくてもそれらを解決するのは難しいです。しかし、最初に私に飛びつくのは、アップデーターフィールドの '' a''です。あなたはここでforallを使いたいのですか?それは非常に便利ではないようです。 – Drup