You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The error message seems to be coming from the internal struct-type property: in particular, note that (object-name dict?) is 'dict (there is no gen:dict?) and #hash() satisfies dict?.
Strictly speaking, getting some error here is consistent with the docs for impersonate-generics, which state that the supplied value "must be a structure that implements the generic interface", but I did not realize that meant the value "must be a structure" specifically. In fact, AFAICT from the implementation, "must be a structure" even more specifically means that the structure type must be created with the internal property attached, either via #:methods or make-struct-type-property/generic/make-generic-struct-type-property: structures handled via #:defaults or #:fast-defaults are not supported. There doesn't seem to be any public API to test for this requirement short of catching and trying to recognize exceptions.
At a minimum, the error message should be fixed, and I think the docs should be clarified.
I can also see at least two reasons to consider changing the behavior:
In Racket in general, conceptually "everything is a struct" under some sufficiently-powerful inspector. Treating structs differently than non-structs is unusual.
A programmer who wants to interpose on generic methods and doesn't want to hard-code special cases for the currently-supported non-structs can currently do so by creating some wrapper struct that implements the interface by simply bouncing each method through the generic version with define/generic. Even if it used essentially that implementation strategy, an implementation in racket/generic would be much more ergonomic, since racket/generic already knows the complete list of methods (including optional methods that may be added over time), the arity of each method, and which is the "this" argument to each.
The text was updated successfully, but these errors were encountered:
This program:
produces the following error:
The error message seems to be coming from the internal struct-type property: in particular, note that
(object-name dict?)
is'dict
(there is nogen:dict?
) and#hash()
satisfiesdict?
.Strictly speaking, getting some error here is consistent with the docs for
impersonate-generics
, which state that the supplied value "must be a structure that implements the generic interface", but I did not realize that meant the value "must be a structure" specifically. In fact, AFAICT from the implementation, "must be a structure" even more specifically means that the structure type must be created with the internal property attached, either via#:methods
ormake-struct-type-property/generic
/make-generic-struct-type-property
: structures handled via#:defaults
or#:fast-defaults
are not supported. There doesn't seem to be any public API to test for this requirement short of catching and trying to recognize exceptions.At a minimum, the error message should be fixed, and I think the docs should be clarified.
I can also see at least two reasons to consider changing the behavior:
define/generic
. Even if it used essentially that implementation strategy, an implementation inracket/generic
would be much more ergonomic, sinceracket/generic
already knows the complete list of methods (including optional methods that may be added over time), the arity of each method, and which is the "this" argument to each.The text was updated successfully, but these errors were encountered: