Zedrikov has quit [Remote host closed the connection]
nimred has joined #ocaml
Zedrikov has joined #ocaml
Zedrikov has quit [Remote host closed the connection]
Zedrikov84 is now known as Obelix_
Zedrikov has joined #ocaml
Zedrikov has quit [Remote host closed the connection]
Zedrikov has joined #ocaml
Zedrikov has quit [Remote host closed the connection]
Zedrikov has joined #ocaml
Zedrikov has quit [Remote host closed the connection]
Obelix_ has quit [Quit: Bye all, see you next time!]
JuzorBNC has quit [Read error: Connection reset by peer]
fraggle_ has quit [Remote host closed the connection]
fraggle_ has joined #ocaml
avsm has joined #ocaml
avsm has quit [Ping timeout: 265 seconds]
avsm has joined #ocaml
lihaitao has joined #ocaml
lihaitao has quit [Quit: bed]
cdidd has quit [Remote host closed the connection]
snearch has joined #ocaml
eikke has joined #ocaml
eikke has quit [Ping timeout: 245 seconds]
eikke has joined #ocaml
albacker_ has joined #ocaml
albacker has quit [Read error: No route to host]
albacker_ is now known as albacker
albacker has quit [Changing host]
albacker has joined #ocaml
albacker is now known as eni
xlq has quit [Ping timeout: 260 seconds]
xlq has joined #ocaml
emmanuelux has joined #ocaml
apropos has joined #ocaml
xlq has quit [Ping timeout: 260 seconds]
apropos is now known as xlq
<xlq>
I wanted a hash table keyed physically, so I decided to define an 'a -> int function as:
<xlq>
let id x = 0 + Obj.magic x
<xlq>
however, if I print the id of an object in the ocaml REPL, and then compare: (id x) = <number it printed>, it always evaluates to false.
<Lor>
That's because (id x) still has the int tag bit set, while a numeric literal doesn't.
<Lor>
Also, gc might move x to a new location.
<Lor>
Sorry, id x _doesn't_ have the int tag bit while a numeric literal does.
<Lor>
But that's only if x is heap-allocated.
<Lor>
For instance (id true = 1) evaluates to true.
<mrvn>
Obj.magic x doesn't set the tag but assumes it is set. so 0 + ... will add the two values and substract one tag.
<mrvn>
So if x isn't int the wrong thing comes out
<xlq>
OK, so maybe this isn't the best way to have a physically keyed map.
<mrvn>
xlq: why not define your cmp function to use physical equality?
<xlq>
Hashtbl doesn't take a cmp function.
<mrvn>
module Make:
<mrvn>
functor (H : HashedType) -> S with type key = H.t
<mrvn>
Functor building an implementation of the hashtable structure.
<xlq>
Um, missed that :P
<xlq>
Thanks
<Lor>
mrvn, Obj.magic doesn't assume anything, but + does.
<mrvn>
you only need equality which you can do physical
<xlq>
Although I still need a hash function based on physical equality
<mrvn>
Lor: nah, Obj.magic assumes you know what you do.
<mrvn>
xlq: I don't think that is possible. The address of an object isn't constant so you can't hash by that
<xlq>
I see.
<mrvn>
xlq: all entries with the same value will end up in the same bucket but you can use physical equality to keep them chained as different entries.
<xlq>
Yeah.
<Lor>
let id x = Obj.magic x lxor 0
<Lor>
seems to work.
<mrvn>
Lor: no
<Lor>
It works in the sense of producing a proper int.
<xlq>
Something else I could do would be to attach ids to all my types that I want to have identities.
<Lor>
xlq, objects have that already.
<mrvn>
# id ();;
<mrvn>
- : int = 0
<mrvn>
# id 0;;
<mrvn>
- : int = 0
<mrvn>
# id [];;
<mrvn>
- : int = 0
<Lor>
mrvn, what are you trying to demonstrate?
<xlq>
Lor: Objects have IDs? Really?
<mrvn>
Lor: that you aren't getting any kind of reliable id
<Lor>
Yeah.
<flux>
xlq, Oo.id
<flux>
works for actual objects, not plain values :)
<Lor>
mrvn, if you want to demonstrate that, you should be using heap-allocated values before and after gc.
<xlq>
Oh, but just for objects.
<xlq>
Yeah.
<mrvn>
Lor: that too
tlockney has joined #ocaml
eikke has quit [Ping timeout: 246 seconds]
emmanuelux has quit [Quit: @+]
ggherdov has joined #ocaml
ggherdov has left #ocaml []
eikke has joined #ocaml
skchrko has quit [Quit: ChatZilla 0.9.88.2 [Firefox 11.0/20120401163544]]
eni has quit [Quit: .]
emmanuelux has joined #ocaml
shachaf has left #ocaml []
snearch has quit [Quit: Verlassend]
emmanuelux has quit [Remote host closed the connection]
emmanuelux has joined #ocaml
eikke has quit [Ping timeout: 272 seconds]
andreypopp has quit [Quit: Computer has gone to sleep.]