Re: meta-comment on typing
John.Cowan 06 Oct 2005 19:08 UTC
Per Bothner scripsit:
> * As a matter of style, I believe type declarations are preferable to
> type-specific arithmetic primitives, especially since Type Declarations
> are Good in themselves.
On reflection, my real objection to hiding type-specific primitives behind
type declarations is that it makes the primitives not first-class: given
that a and b are declared fixnum, only calls that can be recognized as
calls on + are rewritten as calls on fx+.
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.
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).
If there are worries about namespace pollution, that could be resolved by adding
a procedure IFFIXNUM that maps a generic procedure to its fixnum-specific
alternative: ((fixnum +) 3 4) is fixnum-specific addition, and so is
(apply (fixnum +) '(3 4)).
--
A few times, I did some exuberant stomping about, John Cowan
like a hippo auditioning for Riverdance, though xxxxxx@reutershealth.com
I stopped when I thought I heard something at www.ccil.org/~cowan
the far side of the room falling over in rhythm www.reutershealth.com
with my feet. -- Joseph Zitt