[racket] Typed Racket HashTable vs Racket HashTable
Andrey, you could write your own function like this:
(define (hashes-equal? h0 h1)
(for/and ([k (in-list (hash-keys h0))])
(and (hash-has-key? h1 k)
(equal? (hash-ref h0 k) (hash-ref h1 k)))))
This should work in general.
If you know that the two hashes use a specific comparison function
other than `equal?`, such as `eq?`, this function could use that
function in its last line and be faster. But in general you don't
know, so the above would be the general thing that works in all cases.
Actually here's a variation where you can pass the comparison
function, but it defaults to `equal?`:
(define (hashes-same? h0 h1 [? equal?])
(for/and ([k (in-list (hash-keys h0))])
(and (hash-has-key? h1 k)
(? (hash-ref h0 k) (hash-ref h1 k)))))
On Mon, Apr 8, 2013 at 11:16 AM, Andrey Larionov <anlarionov at gmail.com> wrote:
> Right now i'm understand my mistake. Is there any function to perform
> equality check between mutable and immutable hash-tables?
>
> On Mon, Apr 8, 2013 at 7:06 PM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:
>>
>> is is actually not a bug. In your example, the TR code creates an
>> immutable hash literal with `#hash`. The untyped code uses `make-hash`
>> to create a mutable hash. Mutable and immutable hashes cannot be equal
>> under `equal?`.
>
>
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>