[racket] generics + superstructs

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Fri Mar 15 11:15:13 EDT 2013

This is not currently possible.

Currently, when a substruct defines methods, it replaces the entire
method table, and any non-implemented methods are considered absent.

I agree with you, though, that inheriting methods from superstructs
would be a better design. I've added it to the generics to-do list.

In the meantime, you can work around this by abstracting the body of
`some-base-stuff' into a separate functions, say `base-stuff', and then
using that function as the method (`(define some-base-stuff base-stuff)')
for both struct types.

Vincent



At Wed, 13 Mar 2013 20:39:01 +0400,
Dmitry Pavlov wrote:
> 
> Hello,
> 
> In short: I use inheritance of structures, I use structure generics,
> but I can not combine inheritance and generics in the way that seems
> the most natural.
> 
> 
> #lang racket
> 
> (require racket/generic)
> 
> (define-generics my
>    (some-base-stuff my)
>    (some-specific-stuff my))
> 
> (struct base
>    (base-field)
>    #:methods gen:my
>    ((define (some-base-stuff my)
>       (print (base-base-field my)))))
> 
> (struct specific base
>    (specific-field)
>    #:methods gen:my
>    ((define (some-specific-stuff my)
>       (print (specific-specific-field my)))))
> 
> (some-base-stuff (specific 2 4))
> 
> some-base-stuff: not implemented for #<specific>
> 
> 
> Can generic #:methods be possibly inherited from superstructure?
> 
> 
> 
> Best regards,
> 
> Dmitry
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.