Because in function `b`, the type of the `lambda` that `n` actually be
passed to is the union of `add1` and `sub1` in the context,
hence, the info on parity of `n` are lost before this `lambda` is evaluated.

On Sat, Sep 10, 2016 at 3:42 AM, Jos Koot <jos.k...@gmail.com> wrote:

> #lang typed/racket
>
> (define (a (n : Exact-Nonnegative-Integer)) : Exact-Nonnegative-Integer
>  (if (even? n) (add1 n) (sub1 n)))
>
> (define (b (n : Exact-Nonnegative-Integer)) : Exact-Nonnegative-Integer
>  ((if (even? n) add1 sub1) n))
>
> Function a goes well,
> but function b gives an error during expansion:
>
> Type Checker: type mismatch
>   expected: Nonnegative-Integer
>   given: Integer in: ((if (even? n) add1 sub1) n)
>
> Apparently the type checker deduces that in function a,
> sub1 will not be applied to zero.
> Why it can't also detect this for function b?
>
> Thanks, Jos
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to