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

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Fri Sep 6 10:13:50 EDT 2013

Asumu Takikawa writes:

 > You can write the method implementations as plain function definitions
 > in some module, e.g.,
 > 
 >   (define (my-dict-ref ...) ...)
 >   ...
 >   (provide my-dict-ref ...)
 > 
 > and then in each structure you can do
 > 
 >   (struct particular-dict (...)
 >     #:methods
 >     [(define dict-ref my-dict-ref)
 >      ...])
 > 
 > to share the implementations.

That looks so obvious once you see it... Thanks a lot!

Konrad.

Posted on the users mailing list.