<div dir="ltr"><div><div><div>You can sort of fake it if you wrap your function in a structure type. In lieu of <br><br></div>(define-type T1 (Symbol -> String))<br><br></div>Instead use a struct:.<br><div><br>(struct: T1 ([f : (Symbol -> String)]))<br>
<br></div><div>;; predicate is T1? for a wrapped Symbol->String function<br></div><div><br>(define-type T2 (U Symbol Number T1)) ;; T1 is a boxed function of Symbol->String<br><br>(: yup (T2 -> String))<br>(define (yup t2)<br>
(cond<br> ((symbol? t2) (symbol->string t2))<br> ((number? t2) (number->string t2))<br> (else (match t2<br> ((T1 f) (f 'goodbye))))))<br><br>(yup 'hello)<br>(yup 123)<br>(yup (T1 symbol->string))<br>
<br></div>And
I don't know but maybe it would be possible for a sufficiently smart
compiler to elide the T1 boxing and unboxing of the wrapped function.<br></div>Well for that matter eliding any single wrapped value type.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 21, 2013 at 9:54 AM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
(And this is not a limitation of Typed Racket but a fundamental problem of CS.)<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On May 20, 2013, at 11:07 AM, Eric Dobson <<a href="mailto:eric.n.dobson@gmail.com">eric.n.dobson@gmail.com</a>> wrote:<br>
<br>
> No, you cannot define predicates for function types. If you explain<br>
> the problem you have, we might be able to explain another solution<br>
> that will work.<br>
><br>
> On Mon, May 20, 2013 at 1:32 AM, Paul Leger <<a href="mailto:pleger@gmail.com">pleger@gmail.com</a>> wrote:<br>
>> Hi all,<br>
>> Maybe, this question is very easy. In the following code, I try<br>
>> defining a predicate for T2, but I cannot because T1 it is a function.<br>
>><br>
>> (define-type T1 (Symbol -> Any) )<br>
>> (define-type T2 (U Symbol Number T1))<br>
>><br>
>> ;(define-predicate T1? Procedure) ;this line is useless<br>
>><br>
>> (define-predicate T2? T2)<br>
>><br>
>>> Type Checker: Type T2 could not be converted to a contract. in: T2<br>
>><br>
>> My unsuccessful answer is:<br>
>> (define-type T2 (U Symbol Number Procedure))<br>
>><br>
>> I do not like it because I lose the relationship between T1 and T2. Are<br>
>> there some possibility<br>
>><br>
>> Thank in advance,<br>
>> Paul<br>
>><br>
>> ____________________<br>
>> Racket Users list:<br>
>> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
>><br>
> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>