Parameter polymorphic


#1

Hello,

Someone to help me work with this snippet (https://sketch.sh/s/d1T56NbK6M3tdfREsNkqML/).

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
#2

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 (https://sketch.sh/s/0q4Fv2xXbVeln95wWF8yoq/)