Types ReasonML类型与相同类型不匹配

Types ReasonML类型与相同类型不匹配,types,ocaml,functor,reason,bucklescript,Types,Ocaml,Functor,Reason,Bucklescript,即使我在ReasonML中使用了相同的类型,我也收到了类型不匹配。错误是: [1] We've found a bug for you! [1] /Users/gt/work/real-and-open/frontend/src/domain/classroom/views/RosterLayoutHeader.re 42:10-70 [1] [1] 40 ┆ <Classroom.Mutation.AddStudent> [1] 41 ┆ ...{ [1]

即使我在ReasonML中使用了相同的类型,我也收到了类型不匹配。错误是:

[1]   We've found a bug for you!
[1]   /Users/gt/work/real-and-open/frontend/src/domain/classroom/views/RosterLayoutHeader.re 42:10-70
[1]
[1]   40 ┆ <Classroom.Mutation.AddStudent>
[1]   41 ┆   ...{
[1]   42 ┆     (addStudent: (~id: UUID.t, ~classroomId: UUID.t, unit) => unit) =>
[1]         {
[1]   43 ┆       <div>
[1]   44 ┆         <StudentRowHeader
[1]
[1]   This pattern matches values of type
[1]     (~id: UUID.t, ~classroomId: UUID.t, unit) => unit
[1]   but a pattern was expected which matches values of type
[1]     AddStudent.ContainerMutation.mutationFunctionType (defined as
[1]       AddStudent.MutationInternals.mutationFunctionType)
在代码中,AddStudent如下所示:

[@bs.config {jsx: 3}];
module Mutation = [%graphql
  {|
    mutation addStudent($id: ID!, $classroomId: ID!) {
      addStudent(student: {id: $id, classroomId: $classroomId}){
        ...Classroom_Model.Fragment.ClassroomFields
      }
    }
  |}
];

module MutationInternals : ApolloMutation.MutationInternal = {
  type mutationFunctionType = (~id: UUID.t, ~classroomId: UUID.t, unit) => unit;
  let componentName = "AddStudent";

  module Config = Mutation;
  module InternalMutation = ReasonApollo.CreateMutation(Config);

  let callMutationWithApollo = (apolloMutation : ApolloMutation.apolloMutationType(Config.t)) => 
    ((~id: UUID.t, ~classroomId: UUID.t, ()): unit => {
      let newStudent = Config.make(~id, ~classroomId, ());
      apolloMutation(
        ~variables=newStudent##variables,
        // ~refetchQueries=[|"member"|],
        // ~optimisticResponse=Config.t,
        (),
      ) |> ignore;
      () |> ignore;
    }: mutationFunctionType);
};

module ContainerMutation = ApolloMutation.CreateMutationContainer(MutationInternals);

module Jsx2 = ContainerMutation.Jsx2;
let make = ContainerMutation.make;
所以请注意三件事

1) 类型:
type mutationFunctionType=(~id:UUID.t,~classroomId:UUID.t,unit)=>unit,错误中显示
AddStudent.MutationInternals.mutationFunctionType
(~id:UUID.t,~classroomId:UUID.t,unit)=>unit
不匹配,即使它们相同

2) 当我在调用函数中直接引用类型时,它表示
mutationFunctionType
不是函数,而是函数

3) 我正在使用函子处理我的变异内部模块。。。我想知道这是否会影响类型


谢谢

AddStudent.MutationInternals.mutationFunctionType
类型是抽象的,编译器不知道它实际上是作为类型的函数实现的

(~id: UUID.t, ~classroomId: UUID.t, unit) => unit
很难猜测,你的问题的根源是什么。您可能是通过密封模块意外地过度抽象了代码,或者是试图破坏必要的抽象。在任何情况下,编译器都会阻止您这样做

通常,在密封模块时会发生此类错误,例如,在添加模块类型时,例如

module type S = {type t};
module M : S = { type t = int};
这使得类型
M.t
抽象化,因此它在预期
int
的上下文中不可用。解决方案是移除不必要的密封,例如

module type S = {type t};
module M = { type t = int};
或者明确地告诉编译器,
t
不是抽象类型,而是具体的
int
,例如

module type S = {type t};
module M: S with type t = int = {
  type t = int;
};
注意,在你的情况下,我说的是这段代码

MutationInternals : ApolloMutation.MutationInternal

它隐藏了
mutationFunctionType
定义。

ApolloMutation.MutationInternal
强制它。删除它和一些错误修复了我的问题。谢谢!
MutationInternals : ApolloMutation.MutationInternal