[racket] TR: unwrapping from <#Typed Value: ... > ??

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Fri Nov 25 08:37:53 EST 2011

On Fri, Nov 25, 2011 at 8:28 AM, Ismael Figueroa Palet
<ifigueroap at gmail.com> wrote:
>> 2011/11/25 Sam Tobin-Hochstadt <samth at ccs.neu.edu>
>> This means that you passed the procedure to an untyped module with the
>> type `Any'.  If you provide a more specific type, it won't be wrapped
>> like this.
> Indeed, I was storing a value of type FunType = (Any -> (T Any)) inside a
> continuation mark, and then retrieving it for the comparison. I was
> retrieving the continuation marks with type (Listof Any), using
> continuation-mark-set->list, which I think is the reason for the error I'm
> getting.
> could the continuation mark put the function in the untyped module you
> mention?

Yes, continuation marks are going to be a problem.  Unfortunately,
there's not really anything you can do here, because continuation
marks are an unrestricted channel between all parts of the program.
Any other portion of the program could add things to the continuation
with the same mark, or retrieve your continuation mark.

> However, if I change the expected type to (Listof FunType), I get a type
> error when calling continuation-mark-set->list, which says that this
> functions returns (Listof Any).
> How can I coerce a (Listof Any) into a (Listof FunType)?

You can't.  Given a value, all you can possibly do to it is a
first-order check.  And unfortunately, you can't tell if something is
a particular kind of function using a first-order check.

What I recommend you do here is one of the following:

 - use a parameter instead of a continuation mark.  Parameters have
more structure, and thus can be given better types.
 - or, create an untyped module which does the continuation mark
manipulation you want, and then import the relevant functions from it
with the appropriate types.

> Or more in general, I'm facing similars problems in my code, where I get
> something of type Any and I need to coerce it to a more specific type but I
> can't get it to work. I've tried using ann and assert but it doesn't seems
> to work :-(

`ann' just tells the typecheck what to expect -- it doesn't do any coercion.

`assert' has two forms -- one with a predicate, and one without.  The
second one is just for checking if a value is `#f'.  Which one were
you using, and what didn't work about it?
sam th
samth at ccs.neu.edu

Posted on the users mailing list.