[plt-scheme] polymorphism of primitive types

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Oct 18 10:56:03 EDT 2005

On Oct 18, 2005, at 10:29 AM, Yoav Goldberg wrote:

>>> What I had in mind was something in the lines of:
>>> (define qqh (list->infinite-stream '(quarter quarter half))
>>> (map (lambda (pitch duration) (make-sound 'pitch: pitch 'duration:
>>> duration)
>>>         (list DO RE MI FA SO LA SI)
>>>         qqh)
>> I believe that you don't want infinite lists but rationale ones, i.e.,
>> lists with repeated patterns. These are graphs and you should probably
>> just turn them into graphs:
>> (define qqh (shared ([qqh (cons quarter (cons quarter (cons half
>> qqh)))]) qqh))
>> Have you considered that?
>
> I didn't know about this option. Thanks. I'll consider it. Where's the
> best place to read about it?

Look in Help Desk; it should describe shared. Roughly speaking, shared 
is for data what letrec is for functions (which shows that in Scheme, 
we only create an illusion that lambda is first-class. But so much for 
heresy.)

>> [...]
>> Don't confuse using a module as a language vs making a drscheme
>> language.
>> The former is almost no effort; the latter requires more work.
>
> The problem I have with using a module as a new language is that you
> can only have one of these.
> Let's say I want to reimplement both sequence operations (cons, car,
> cdr..) and arithmetics (+,-,..).

And more.

I don't understand your problem. You said that the new arithmetic will 
subsume the old one. So why would you ever want to use the old one in 
conjunction with the new lists?

There are other solutions, and I believe I see one on the mailing list.

-- Matthias



> At some of my programs I would like to have only the new sequence
> operations, on others only the new arithmetics, and on some of them I
> would like to have both.
> When using module as modules, this can be easily done:
> (module my-prog1 mzscheme
>   (require "my-seq.ss")
>   ..)
> (module my-prog2 mzscheme
>   (require "my-arith.ss")
>   (require "my-seq.ss")
>   ..)
>
> but when using modules as language, I would have to create a new 
> language
> for every combination I want to use..
>
>
> Yoav



Posted on the users mailing list.