[racket] Specifying the type of a function that contains a type test (but isn't one)

From: Jeremiah Willcock (jewillco at osl.iu.edu)
Date: Mon Apr 18 15:02:13 EDT 2011

Given the following Typed Racket program:

#lang typed/racket

(: greater-than-5? (Any -> Boolean))
(define (greater-than-5? x)
   (and (integer? x) (> x 5)))

(: equal-to-7? (Any -> Boolean))
(define (equal-to-7? x)
   (and (greater-than-5? x) (= x 7)))

I receive the error (highlighting the x in (= x 7)):

Type Checker: Expected Complex, but got Any in: x

Is there a way to tag greater-than-5? to mark that it only returns #t on 
integers?  Marking its type as (Any -> Boolean : Integer) causes an error:

Type Checker: Expected result with filter ((Integer @ x) | (! Integer @ 
x)), got filter (((U Float Integer) @ x) | (OrFilter (! Integer @ x) ((U 
Float Integer) @ x))) in: (and (integer? x) (> x 5))

-- Jeremiah Willcock

Posted on the users mailing list.