related to another topic (Using object in a type does not work - 'unbound value' - #9 by mudrz) (ideally I want to avoid the polymorphic 'a
altogether), but why does config1
work, but config2
causes an error:
module MyModule = {
type t<'a> = {value: 'a}
let getConfig = value => {value: value}
@send external doSomething: (int, {..}) => unit = "doSomething"
type myFn<'a> = (int, {..} as 'a) => unit
// works
let config1: t<myFn<{..}>> = {value: doSomething}
// causes an error
let config2: t<myFn<{..}>> = getConfig(doSomething)
}
the full error is:
[ReScript] [E] The type of this module contains type variables that
cannot be generalized:
{
type t<'a> = {value: 'a}
let getConfig: 'a => t<'a>
external doSomething: (int, {..}) => unit = "doSomething" "#rescript-
external"
type myFn<'a> = (int, 'a) => unit
constraint 'a = {..}
let config1: t<myFn<{..}>>
let config2: t<myFn<{_..}>>
}
This happens when the type system senses there's a mutation/side-effect,
in combination with a polymorphic value.
Using or annotating that value usually solves it.
notice that config2
's type is let config2: t<myFn<{_..}>>
, what does the _
even mean?