[racket] [plt-scheme] Re: Typed scheme: Cannot apply expression of type Procedure, since it is not a function type

From: David Van Horn (dvanhorn at ccs.neu.edu)
Date: Mon Jun 7 16:18:30 EDT 2010

On 6/7/10 4:08 PM, keydana at gmx.de wrote:
>> Try the other way around:
>> (truncate (inexact->exact n))
> Finally I've found the time to try this - but it gives me a Real (same with round):
> (truncate (inexact->exact 1.222))
> - : Real
> 1
> So I still have the typing error, the substring function insisting on an Integer...
> One general question...
> Having right now read through the "untyped" http://docs.racket-lang.org/reference/numbers.html page, which introduces the exact vs. inexact concept and the sets of numbers from mathematics as orthogonal, I'd be curious about how TS handles this in the type hierarchy?
> Also, in practice,  think it'd be helpful to show the inclusion hierarchy for numeric types in the typed scheme reference... in fact I just realized that even in my ultra-simplistic representation, where I just want to have one "number" type (like the sql number type), I should think more about which one to use, whether it should be an exact or an inexact one... but I'm not really sure which possibilities there are for both options (e.g., I assume Number and Real are inexact, and Exact-Rational is the farthest I can get away from Integer with exact numbers? -- BTW, Exact-Rational is not in the docs, I just see it in drscheme).


I know that Sam and Vincent are actively developing the numeric part of 
Typed Scheme, so truncate may already have the right type for you in the 
latest sources, but more generally I've found it's useful to insert 
casts when Typed Scheme cannot follow the programmer's reasoning.

So here is one way to make your program work:

(: cast (All (T) ((Any -> Boolean : T) Any -> T)))
(define (cast p? x)
   (if (p? x)
       (error "Cast failed")))

(cast exact-integer? (truncate n))

My backgammon package has some other examples of casts, too.


Posted on the users mailing list.