There’s a certain trick to having higher-rank polymorphic functions, as detailed in this thread.
For your example, you might have to do some extra JS wrapping (or just tweak the implementation) of that proxify function, but it should be doable; see this playground link.