[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: meta-comment on typing



John.Cowan wrote:
For example, if the programmer knows that f is a list of fixnums, there
is no way to apply fixnum addition to them, whereas (apply fx+ f) is trivial.

Well. fx+ as currently specified is binary.
So (apply fx+ f) is equivalent to:
(apply (lambda ((v1 :: <fixnum>) (v2 :: <fixnum>)) (+ v1 v2))
       f)
For a general-length list one can of course use reduce.

Admittedly more tedious.

Similarly, a HOF involving fixnums can't take advantage of fixnum arithmetic:

	(define (op f (x :: fixnum) (y :: fixnum)) (f x y))

will perform generic addition, not fixnum addition, if called as (op + 2 3).

No, it will perform fixnum arithmetic, but fixnum arithmetic will be
selected using a run-time type dispatch.

This requires that integers and fixnums are distinguishable at runtime.
I.e. (eqv? 10 (as <fixnum> 10)) => #f
though: (= 10 (as <fixnum> 10)) => #t
just like: (eqv? 10 10.0) =>f and (= 10 10.0) => #t.

I have mixed feelings about whether fx+ should be in R6RS.
I would like for (fx+ x y) to be equivalent to:
(+ (as <fixnum> x) (as <fixnum) y))

That does require that 10 and (as <fixnum> 10) be different.
This can be partly hidden from implementations that don't have
separate fixnum values, if we define (fixnum? x) as testing
whether x is in the fixnum *range* rather than having the fixnum type.

What I do need to request is this:
(eqv? 5 (fx+ 2 3)) => unspecified
--
	--Per Bothner
per@xxxxxxxxxxx   http://per.bothner.com/