[plt-scheme] polymorphism of primitive types

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Oct 17 23:29:26 EDT 2005

On Oct 17, 2005, at 7:41 PM, Yoav Goldberg wrote:

> Hi,
> I would really like to be able treat my own sequential data (such as
> streams, or trees) as lists, ie, to have "car" "cdr" "map" "list-ref"
> "length" etc work on regular lists as well as on streams (and the
> other relevant data types).
> In python this is really easy - you make a class, define it's
> __iter__() and next() methods, and you can use it anywhere you would
> use a list. Very handy. What's the best way to achieve the same effect
> in MzScheme? (what's the most efficient way to achieve the
> polymorphism, and what is the minimal set of functions I'll be
> required to implement for each new type?)
> Thanks,
> Yoav

Danny's answer is probably all you need.

Let me comment however on the need to co-mingle lists and streams.
It is quite uncommon that the same program fragments need to process
both lists and streams in the same program. If you believe you have
a design that requires just that, please share with us.

I might be tempted to suggest the use of your friend's Eli's
lazy Scheme language in one module and plain Scheme for other
modules if you need what I think you need :-)

-- Matthias

Posted on the users mailing list.