> On Jul 12, 2016, at 4:50 PM, 'John Clements' via Racket Users 
> <racket-users@googlegroups.com> wrote:
> 
> lang typed/racket
> 
> (: process-number (Integer -> (U 'both-odd 'not-both-odd)))
> (define (process-number n)
>  (if (andmap is-odd? (list (sub1 n) (add1 n)))
>      'both-odd
>      'not-both-odd))
> 
> (: is-odd? (Integer -> (U 'odd 'even)))
> (define (is-odd? n)
>  (if (= (modulo n 2) 0)
>      'even
>      'odd))
> 
> (process-number 13) ;; > returns ‘both-odd

> this program suggests that both 12 and 14 are odd numbers. Can you see the 
> bug?


Obviously ‘odd and ‘even are both Truthy values in Typed Racket. This is not a 
bug. This is proof that TR accommodates R. 

Here is the fixed version: 

#lang typed/racket

(: process-number (Integer -> (U 'both-odd 'not-both-odd)))
(define (process-number n)
 (if (andmap (lambda ({x : Integer}) (eq? (is-odd? x) 'odd)) (list (sub1 n) 
(add1 n)))
     'both-odd
     'not-both-odd))

(: is-odd? (Integer -> (U 'odd 'even)))
(define (is-odd? n)
 (if (= (modulo n 2) 0)
     'even
     'odd))

(process-number 13) 

-- 
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