[plt-scheme] How to make unit functors?
Robby Findler wrote:
>I think that the proper interpretation of the prose is:
>
> for any values, v1 and v2,
>
> (eq? v1 v2)
> =>
> (and (number? (eq-hash-code v1))
> (number? (eq-hash-code v2))
> (= (eq-hash-code v1) (eq-hash-code v2)))
>
>The reverse implication may or may not be true (it's usually true, tho.
>Isn't this the usual story for hashing?)
>
That's why I wanted to hear if I was lucky with respect to symbols :-)
I have just checked that even though 'j and 'J are eq?
then have different hash-codes. Thus the reverse definitely does
not hold for symbols.
My idea about fixnums came from this part
The number is an exact integer
that is itself guaranteed to be eq? with any value representing the
same exact integer (i.e., it is a fixnum).
and got the idea that hashing a fixnum f would give a value which
were eq? with any fixnum representing f (and thus also f it self).
Which implies that (eq? f (eq-hash-code f)).
Experiments in the repl didn't provide counter examples.
>(eq-hash-code 42)
42
But on the other hand this proves nothing, since that's just
how eq-hash-code happens to be implemented now.
Thanks,
--
Jens Axel Søgaard
>
>The text goes on to guarantee that this:
>
> (eq? v1 v2)
> =>
> (and (number? (eq-hash-code v1))
> (number? (eq-hash-code v2))
> (eq? (eq-hash-code v1) (eq-hash-code v2)))
>
>which, as the text notes, implies that the numbers are fixnums. Another
>way to put it:
>
> (eq? v1 v2)
> =>
> (and (number? (eq-hash-code v1))
> (number? (eq-hash-code v2))
> (fixnum? (eq-hash-code v1))
> (fixnum? (eq-hash-code v2))
> (= (eq-hash-code v1) (eq-hash-code v2)))
>
>where fixnum? can (I think) be defined as:
>
> (define (fixnum? n)
> (and (number? n)
> (exact? n)
> (integer? n)
> (eq? (- (+ n 1) 1) n)))
>
>I'm not sure why there isn't a fixnum predicate built in (or maybe I
>just missed it?)
>
>Robby
>
>At Wed, 28 May 2003 18:35:05 +0200, =?Windows-1252?Q?Jens_Axel_S=F8gaard?= wrote:
>
>
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>>Matthew Flatt wrote:
>>
>>
>>
>>
>>>>Is the same also true for symbols? That is does it hold for two
>>>>symbols s1 and s2 that
>>>>
>>>> (= (eq-hash-code s1) (eq-hash-code s2)) = (symbol=? s1 s2)
>>>>
>>>>?
>>>>
>>>>
>>>Yes. `symbol=?' is `eq?' with its domain restricted to symbols.
>>>
>>>
>>Sorry, I intended to ask this question:
>>
>> Is the same also true for symbols? That is does it hold for two
>> symbols s1 and s2 that
>>
>> (= (eq-hash-code s1) (eq-hash-code s2)) => (symbol=? s1 s2)
>> ?
>>
>>[otherwise the question is a bit silly]
>>
>>I interpreted the prose describing eq-hash-code as
>>
>>For all fixnums f1 and f2:
>>
>> (= (eq-hash-code f1) (eq-hash-code f2)) => (= f1 f2)
>>
>>and wanted to know if it also holds for symbols.
>>
>>--
>>Jens Axel Søgaard
>>
>>
>>
>>