[racket] Implementing an generic interface outside of a struct definition

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Fri Sep 6 09:46:20 EDT 2013

Vincent St-Amour writes:

 > You can use the `#:defaults' clause of `define-generics' for that. The
 > documentation included in recent snapshots includes examples of its use:
 >     http://www.cs.utah.edu/plt/snapshots/current/doc/reference/struct-generics.html
 > You can also use it to make basic datatypes (strings, numbers, etc.)
 > implement a generic interface.

Great, thanks!

After some further thought, this doesn't really solve my problem since
the default definition needs to be part of the define-generics. The
case I am looking at is gen:dict, which is already defined elsewhere.

I do understand that implementing an already existing interface for an
already existing struct can pose a problem, since multiple library
modules could try to provide such an implementation and thus be in
conflict. But that's not really my situation either because I work on
my own structures. The reason for wanting to implement the methods
separately is plain economy: I have five structures that can use a
strictly identical implementation for gen:dict, and I want to write
the code only once.

So my real question is: is there a way to package method definitions
for reuse?


Posted on the users mailing list.