Thanks,
I already had a hunch in the direction of your answer.
In function b the problem seems to be that subexpression
(if (even? n) add1 sub1)
seems to be reduced without info to which the argument it will be applied.
Nevertheless I wonder whether or not it would be possible
to have the typechecker look one level higher.
After all, after evaluating (if (even? n) add1 sub1)
with zero n, it is clear that sub1 will not be applied to zero
if the argument n is inspected as well.
Probably I am asking too much.
Thanks again, Jos

  _____  

From: WarGrey Gyoudmon Ju [mailto:juzhenli...@gmail.com] 
Sent: viernes, 09 de septiembre de 2016 22:21
To: Jos Koot
Cc: Racket Users
Subject: Re: [racket-users] typed racket confusion


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+unsubscribe@
<mailto:racket-users+unsubscr...@googlegroups.com> googlegroups.com.
For more options, visit https://groups.google.com/d/ 
<https://groups.google.com/d/optout> 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