Parameter polymorphic



Someone to help me work with this snippet (

I would want that param creator (at line 11) to always be polymorphic. However, from the first use, the type specializes and I therefore get an type error.

ReasonReact - handling actions with parametized types

I found my answer on the discord:

@octachron replied:

Your function func is second-rank polymorphic, higher-rank polymorphism are not directly supported in OCaml, you need to use a record with a universally quantified field:

type creator = { creator: 'a. (string, 'a) => user('a) };
let func = ({creator}) => {
  let u1 = creator("joseph", 1);
  let u2 = creator("joseph", "2");
  (u1, u2);

Here sketch solution (