On Tue, Oct 1, 2019 at 10:21 PM David Storrs <david.sto...@gmail.com> wrote:

> For example, there's a hash, hasheqv, and hasheq.  Is there a way to
> have a hash with a user-provided key-comparison function?
>

You probably want `define-custom-hash-types` and the related functions:
https://docs.racket-lang.org/reference/dicts.html#(form._((lib._racket%2Fdict..rkt)._define-custom-hash-types))
More generally, you can of course use `gen:dict` to do exactly what you
want. There are corresponding options for sets, also.


> Is it possible to put gen:equal+hash on something other than a struct?


In general, this would mean redefining how `equal?` works on built-in
datatypes, which would cause trouble for libraries that use those types.
You can choose what `equal?` means for datatypes you define, and you can
choose to use some other notion of equality on datatypes you're comparing,
but you can't mess with what `equal?` means when other people's code calls
it on other people's datatypes.

One alternative that can sometimes make sense is creating a wrapper struct
that basically is just there to hang methods like `gen:equal+hash` on.

-Philip

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAH3z3gYLP3rqFxyf-ua%3DL9rjqiw4-mORZEBUqnOcbb7q-AdC6w%40mail.gmail.com.

Reply via email to