[racket] [typed racket] type case
Does typed racket fail to typecheck because cond will return void on negative numbers or something more related to exhaustive checking regardless of return value?
-Ian
----- Original Message -----
From: Sam Tobin-Hochstadt <samth at ccs.neu.edu>
To: Eric Tanter <etanter at dcc.uchile.cl>
Cc: Racket Users <users at racket-lang.org>
Sent: Thu, 20 Oct 2011 14:39:19 -0400 (EDT)
Subject: Re: [racket] [typed racket] type case
There are basically two options here:
1. If you just use `cond' with no `else', you get a type error when
your cases are not exhaustive. For example:
(: f ((U String Integer) -> Boolean))
(define (f x)
[(string? x) (string=? x "hi")]
[(exact-nonnegative-integer? x) (= x 7)])
This program will fail to typecheck.
2. For the particular case of the PLAI `cases' form, Eli and I have
built something for his class which uses Typed Racket, but the
exhaustiveness checking is done by `cases' itself. Lots more about
that is available from Eli's class web page [1], and I'm sure he'd be
happy to give you the code.
[1] http://pl.barzilay.org/
On Thu, Oct 20, 2011 at 10:48 AM, Eric Tanter <etanter at dcc.uchile.cl> wrote:
> Hi again,
>
> Is there a mechanism to do an exhaustive type case?
>
> I know I can use (cond [(type-pred? v) ...]
> [...])
>
> but of course I have no guarantee that I am exhaustive (and of course, doing pattern matching to destruct the value would be even nicer).
>
> Basically, I guess I'm after the typed version of PLAI's type-case.
>
> Thanks,
>
> -- Éric
>
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users
>
--
sam th
samth at ccs.neu.edu
_________________________________________________
For list-related administrative tasks:
http://lists.racket-lang.org/listinfo/users