I'm getting a signature mismatch in ReasonML between a type I defined which resolves to type mutationFunctionType = (~id: UUID.t, ~classroomId: UUID.t, unit) => unit;
and 'a
which I'm expecting. (seen below).
[1] Signature mismatch:
[1] ...
[1] Values do not match:
[1] let callMutationWithApollo:
[1] ApolloMutation.apolloMutationType(Config.t) => mutationFunctionType
[1] is not included in
[1] let callMutationWithApollo:
[1] ApolloMutation.apolloMutationType(Config.t) => 'a
I'm curious about why I'm receiving this error because I thought the polymorphic type `a could be treated as basically an any type.
Thanks
Type polymorphism allow you to write functions generically in some types.
For instance the polymorphic identity has type 'a => 'a
.
It means it can be used at type int => int
or bool => bool
by instantiating 'a
.
However, this 'a
does not mean anything goes. It only works in one direction:
'a
can become anything, but anything cannot become 'a
.
So from ApolloMutation.apolloMutationType(Config.t) => 'a
you can indeed get
ApolloMutation.apolloMutationType(Config.t) => mutationFunctionType
but what you're doing is the opposite.
For instance you cannot turn an int => int
function into a int => 'a
function.
By the way, providing such a function of type int => 'a
or ApolloMutation.apolloMutationType(Config.t) => 'a
is not really possible unless it returns errors or does not terminate. So I suggest updating your signature if possible to explicitly mention mutationFunctionType
.