[plt-scheme] Type scheme annotations and macros

From: Sam TH (samth at ccs.neu.edu)
Date: Wed Oct 22 10:34:05 EDT 2008

On Wed, Oct 22, 2008 at 10:05 AM, David Van Horn <dvanhorn at ccs.neu.edu> wrote:
> A couple quick questions on Typed Scheme:
>
> 1) Why does the first type-check while the latter does not?
>
> #lang typed-scheme
> (if #f
>    (add1 "dog")
>    'ok)
>
> #;
> (if (ann #f #f)
>    (add1 "dog")
>    'ok)

That looks like a bug.  Can you file it in the bug database?

> 2) How can I write a `bif' macro that works like Typed Scheme's if (ie.
> types its branches with occurrence typing), but forces the conditional value
> to be a Boolean and nothing but a Boolean?
>
> (define-syntax bif
>  (syntax-rules ()
>    [(bif e0 e1 e2)
>     (if (ann e0 Boolean)
>         e1
>         e2)]))
>
> This enforces a Boolean type on e0, but seems to destroy the occurrence
> typing of e1 and e2.

This is tricky, because the type of `e0' is what contains the
occurence typing information, so annotating it with `Boolean' loses
that information.  I'll have to think about this more.

Thanks,
-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.