<br><br><div class="gmail_quote">2011/12/2 Sam Tobin-Hochstadt <span dir="ltr"><<a href="mailto:samth@ccs.neu.edu">samth@ccs.neu.edu</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Fri, Dec 2, 2011 at 6:26 PM, Ismael Figueroa Palet<br>
<<a href="mailto:ifigueroap@gmail.com">ifigueroap@gmail.com</a>> wrote:<br>
> Sam, first I want to thank you for all your answers, you've helped me a lot.<br>
> Thanks!<br>
><br>
>> > I'm trying to implement a function wrapper, that given any function<br>
>> > returns<br>
>> > a function of the same type, but that maybe applies a different<br>
>> > argument. So<br>
>> > far I haven't been successful, and based on previous questions to the<br>
>> > mail<br>
>> > list it seemed that I needed to go to an untyped module because I<br>
>> > couldn't<br>
>> > constraint values to a given type.<br>
>><br>
>> In general, I don't think that any solution is going to work here.<br>
>> You can't take arbitrary functions and apply them to specific<br>
>> arguments (such as the string "blabla") in a type-safe way.<br>
><br>
><br>
> For what I know, the design goal of Typed Racket is to avoid all runtime<br>
> errors. Maybe that is too strict for programs like the one I intend to make.<br>
> The idea of proposing a cast operation is to be able to establish a tradeoff<br>
> between type safety and expressive power, according to the programmer needs.<br>
><br>
>><br>
>> In you particular example, the function `f' is a constant function.<br>
>> But what if it expected `Integer' as its argument? Then your untyped<br>
>> code would be violating the type invariants.<br>
><br>
><br>
> I think in that case a contract violation error should happen (?)<br>
><br>
>><br>
>><br>
>> However, you can make your program work just by removing the<br>
>> parameterization over `A', and replacing that with `Any'. Then your<br>
>> program is safe, and your untyped module can safely call the function<br>
>> with any value it wants.<br>
><br>
><br>
> In that case, my program can only work with values of type Any, and I'd need<br>
> to make all functions Any -> (T Any) since I can't downcast to any other<br>
> type, but since I'm passing functions as arguments I will have the problem<br>
> of subtyping between functions...<br>
><br>
>> As an additional note, the `CAST' operation you describe below, can't<br>
>> do exactly what you expect, because it's runtime semantics depends on<br>
>> how you instantiate `B'. But that would mean that you'd have to<br>
>> generate code for the `CAST' without knowing what `B' is.<br>
><br>
><br>
> do you think it can work if I do (CAST f (Integer -> Boolean)) instead?<br>
<br>
</div></div>Yes, this could work. I haven't added `cast' yet, but I'll try to do that soon.<br>
<div class="im"><br>
> Maybe the flaw in my reasoning is that I think that when you evaluate the<br>
> polymorphic function, then you know what A and B are... so you should be<br>
> able to cast a value to B, is not that so?<br>
><br>
> is it that you statically prove that the body is OK for all A and B and then<br>
> you don't get that information when applying??<br>
<br>
</div>Yes, this latter description is how Typed Racket works.<br>
<div class="im"><br>
>><br>
>> Typed<br>
>> Racket, like ML or Haskell, doesn't pass type parameters around as<br>
>> values, so you can't do this.<br>
><br>
><br>
> I don't know much about how the type system of ML or Haskell works.<br>
><br>
> What I'm trying to do, so you get the full picture, is to write a variation<br>
> of Aspect Scheme in Typed Racket, so you can statically check that advice is<br>
> well-typed. I couldn't type correctly the weaver function, so I tried with<br>
> an untyped module. Maybe it is not possible at all??<br>
<br>
</div>That sounds neat. However, I'm suspicious that you won't be able to<br>
type check everything that people currently write in Aspect Scheme<br>
without changing some part of Typed Racket to understand your system<br>
better.<br></blockquote><div><br>It seems so... the biggest problem for now is that either I can't construct the woven function with the same type as the original one, or I can't apply it :-p (the problem at the origin of the thread)<br>
<br>I think the weaver should have type (All (A B) ((A -> B) jp aspect-env -> (A -> B))) and that's what I've been trying to do, unsuccesfully.<br><br>Any ideas for a reduced version that might work?<br><br>
I was thinking of using a union type with a certain subset of types, and then manually check one-by-one to produce the expected result.<br><br>Thanks<br clear="all"></div></div><br>-- <br>Ismael<br><br>