Greetings,<br><br>I&#39;m trying to implement a function wrapper, that given any function returns a function of the same type, but that maybe applies a different argument. So far I haven&#39;t been successful, and based on previous questions to the mail list it seemed that I needed to go to an untyped module because I couldn&#39;t constraint values to a given type.<br>
<br>With this approach I encountered a problem, that originates in the contracts for polymorphic functions, I made a minimal example of my problem below:<br><br>Module1<br>#lang racket<br>; (All (A B) ((A -&gt; (T B)) A -&gt; (T B)))<br>
(define (untyped-wrap fun value)<br>  (fun &quot;blabla&quot;))<br><br>(provide untyped-wrap)<br><br>Module2<br>#lang typed/racket<br>(struct: (A) T ([value : A]))<br><br>(require/typed &quot;untyped-wrap.rkt&quot;<br>               [untyped-wrap (All (A B) ((A -&gt; (T B)) A -&gt; (T B)))])<br>
<br>(: wrap (All (A B) ((A -&gt; (T B)) A -&gt; (T B))))<br>(define (wrap fun value)<br>  (untyped-wrap fun value))<br><br>(: f (Any -&gt; (T One)))<br>(define (f x) (T 1))<br><br>When I, from the typed Module1, evaluate:<br>
<br>(wrap f 1)<br><br>I get the error:<br><br>untyped-wrap: self-contract violation, expected a(n) A16; got: &quot;blabla&quot;<br>  contract from: (interface for untyped-wrap), blaming: (interface for untyped-wrap)<br>  contract: <br>
    (recursive-contract<br>     (parametric-&gt;/c<br>      (A16 B17) .......<br><br>My guesses:<br><br>First I thought that this should work because at the time I apply untyped-wrap it is known that A = Any and B = One. But then I realized that the typesystem can&#39;t prove that &quot;blabla&quot; is the right type for all A. <br>
<br> Then I thought about instantiating the polymorphic function this way:<br><br>(: wrap (All (A B) ((A -&gt; (T B)) A -&gt; (T B))))<br>(define (wrap fun value)<br>
  ( (inst untyped-wrap A B) fun value))<br><br>guessing again that A = Any and B = One should be known<br><br>but it fails with the same error....<br><br>When I write the concrete types it works.<br><br>I&#39;ve been trying to write code to deal with functions in a general way, while preserving the type, but it seems very hard to do right now in typed/racket :-(<br>
<br>For instance, I had to make an ad-hoc cast going to an untyped module to implement a function with type<br>(All (C D) (EL (C -&gt; (EL D))) -&gt; (EL (C -&gt; (EL D)))), and then I tried the same approach here, but this new error came up<br>
<br>I think it should be useful to provide a &#39;cast&#39; operation. I think then I could say something like, relying on contracts for checking at runtime:<br><br>Module2<br>#lang typed/racket<br>(struct: (A) T ([value : A]))<br>
<br>(require/typed &quot;untyped-wrap.rkt&quot;<br>               [untyped-wrap (Procedure Any -&gt; (T Any))])<br>(: wrap (All (A B) ((A -&gt; (T B)) A -&gt; (T B))))<br>(define (wrap fun value)<br>  [CAST (untyped-wrap fun value) (T B)])<br>
<br>(: f (Any -&gt; (T One)))<br>(define (f x) (T 1))<br><br clear="all">any suggestions on how can I achieve the behavior I want??<br><br>Thanks<br><br>-- <br>Ismael<br><br>