Explicitly stating the type parameter of a generic function

I’m trying to call a generic function in a situation where the compiler can’t infer the type of the argument. I’d like to explicitly instantiate the function with a specific type without creating a local variable for the argument. I want something like “myfunc” in Typescript. Here is a code sample with the compilation error I’m seeing: https://rescript-lang.org/try?code=LYewJgrgNgpgBAFwJ4Ad4DEQjgXjgbwCg5FV4FcC4A3AQyghgC44BLAOwoF9i5YKAZhHYBjFgAoA5LQCUuAHxwARliiEehQqEiw4AIVoAnSuL0tMIOTkVES-OENEA1epT0A6RyPH4a9RiwALABMXDLqmgD0kXAAgggIMMAoFEq0AM4wYHAg7HAAFgko6UzRAiCGEMDuhjDpIoasKQC0ULTsAObuFR2RCH1kIvkwIgDWMIatIJnpzQjDzShQIAjNAO6s883a0DCRwQCMAOwArJGBhJEAVFrgu-pGJmZwFlY2vPZeLlBunsLevgs7gQ7joDGYcBCcDCESukSiMQA6hVRkYQMIwO44ABJOBrdoUBDYWjUECsbLzeAAInsRg6VL4HHgrAEcBQ03SrCUsFuOngBmMeFM5iwbwIHxgFDpLA8FDwvjBAUhoQlgn+31+XnEdPCPCAA.

Is this possible?

Yes, look at the error message:

The record field value can't be found.
  
  If it's defined in another module or file, bring it into scope by:
  - Prefixing it with said module name: TheModule.value
  - Or specifying its type: let theValue: TheModule.theType = {value: VALUE}

Let’s try the first suggestion:

module type Foo = {
  type t = { value: int }
  let func: ('a) => bool
}

module Bar = (B: Foo) => {
  let funcVal = B.func({B.value: 42})
}

And this works fine.

3 Likes