|
List Info
Thread: "ocaml_beginners"::[] Ocam reference to string
|
|
| "ocaml_beginners"::[] Ocam
reference to string |
  Portugal |
2007-05-11 02:40:21 |
|
Hello,
Is their any way one can get hold of a string representation of an Ocaml
reference? My problem is that I want to show (using Graphviz) a graph
like structure however the nodes within this structure have the same
key values so I cannot use these to label and therefore differentiate
the various nodes.
TIA,
Hugo F.
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] Ocam
reference to string |
  United Kingdom |
2007-05-11 02:41:48 |
|
On Friday 11 May 2007 08:40, Hugo Ferreira wrote:
> Hello,
>
> Is their any way one can get hold of a string representation of an Ocaml
> reference?
You could create an association list mapping physical values (i.e. use assq)
onto strings.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?e
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] Ocam
reference to string |
  Portugal |
2007-05-11 03:32:18 |
|
Hello,
Jon Harrop wrote:
> On Friday 11 May 2007 08:40, Hugo Ferreira wrote:
>> Hello,
>>
>> Is their any way one can get hold of a string representation of an Ocaml
>> reference?
>
> You could create an association list mapping physical values (i.e. use assq)
> onto strings.
>
Thanks. I was thinking of something in the lines of a hash function such
as the Digest, but Digest does not seem to accept references.
One additional issue: if I wanted to use Map for example in case of a
very large data structure, how would I then code "compare"? I mean this
is not a simple true/false value using ==. I require an ordering here
using =, >, <.
TIA,
Hugo F.
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] Ocam
reference to string |
  United States |
2007-05-11 10:56:32 |
|
On Fri, 11 May 2007, Hugo Ferreira wrote:
> Thanks. I was thinking of something in the lines of a hash function such
> as the Digest, but Digest does not seem to accept references.
What about Marshal.to_string? That won't distinguish between refs with
the same contents, though.
William D. Neumann
---
"There's just so many extra children, we could just feed the
children to these tigers. We don't need them, we're not doing
anything with them.
Tigers are noble and sleek; children are loud and messy."
-- Neko Case
Life is unfair. Kill yourself or get over it.
-- Black Box Recorder
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] Ocam
reference to string |
  Portugal |
2007-05-11 11:04:36 |
|
William D. Neumann wrote:
> On Fri, 11 May 2007, Hugo Ferreira wrote:
>
>> Thanks. I was thinking of something in the lines of a hash function such
>> as the Digest, but Digest does not seem to accept references.
>
> What about Marshal.to_string? That won't distinguish between refs with
> the same contents, though.
>
Unfortunately that is exactly what I need.
I have done as Jon suggested. Works ok.
Pity we don't have this possibility though.
Hugo F.
> William D. Neumann
>
> ---
>
> "There's just so many extra children, we could just feed the
> children to these tigers. We don't need them, we're not doing
> anything with them.
>
> Tigers are noble and sleek; children are loud and messy."
>
> -- Neko Case
>
> Life is unfair. Kill yourself or get over it.
> -- Black Box Recorder
>
>
> Archives up to November 11, 2006 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
> The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
> Attachments are banned and you're asked to be polite, avoid flames etc.
> Yahoo! Groups Links
>
>
>
>
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] Ocam
reference to string |
  Belgium |
2007-05-11 14:50:13 |
|
Hugo Ferreira wrote:
> Hello,
>
> Jon Harrop wrote:
>
>> On Friday 11 May 2007 08:40, Hugo Ferreira wrote:
>>
>>> Hello,
>>>
>>> Is their any way one can get hold of a string representation of an Ocaml
>>> reference?
>>>
>> You could create an association list mapping physical values (i.e. use assq)
>> onto strings.
>>
>>
>
> Thanks. I was thinking of something in the lines of a hash function such
> as the Digest, but Digest does not seem to accept references.
>
> One additional issue: if I wanted to use Map for example in case of a
> very large data structure, how would I then code "compare"? I mean this
> is not a simple true/false value using ==. I require an ordering here
> using =, >, <.
>
> TIA,
> Hugo F.
>
>
One good reason that can be done, is because the garbage collector can
move things around. So address comparison using == is sound (things
don't get duplicated or merged), but < or > address comparison would be
unsound (the result may change after any garbage collection).
Frédéric
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] Ocam
reference to string |
  United Kingdom |
2007-05-11 21:39:31 |
|
On Friday 11 May 2007 20:50, Frédéric van der Plancke wrote:
> One good reason that can be done, is because the garbage collector can
> move things around. So address comparison using == is sound (things
> don't get duplicated or merged), but < or > address comparison would be
> unsound (the result may change after any garbage collection).
Exactly. The alternative is hideous: you bloat all values with a unique int
tag to differentiate between them. This allows < and > comparisons but makes
your language so slow that you are forced to introduce an artificial
distinction between value and reference types, with the former being the slim
kind of values that OCaml has (without unique IDs), regaining your
performance at the cost of adding unnecessary complexity to the core of the
language.
Then you get into passing semantics: are thing passed by value or by
reference, or by value reference or reference to reference. I just discovered
this hideousness in C# and it really brings home why OCaml/F# are so much
easier to use.
For the one rare case that you want a unique ID on a bunch of values, it is
definitely not worth sacrificing the simplicity of argument passing in all
other cases!!!
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?e
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] Ocam
reference to string |
  Portugal |
2007-05-14 01:57:07 |
|
Frédéric and Jon,
Thanks for the explanations.
Jon Harrop wrote:
> On Friday 11 May 2007 20:50, Frédéric van der Plancke wrote:
>> One good reason that can be done, is because the garbage collector can
>> move things around. So address comparison using == is sound (things
>> don't get duplicated or merged), but < or > address comparison would be
>> unsound (the result may change after any garbage collection).
>
Hmmm... which means the use of hash tables is also not feasible?
> Exactly. The alternative is hideous: you bloat all values with a unique int
> tag to differentiate between them. This allows < and > comparisons but makes
> your language so slow that you are forced to introduce an artificial
> distinction between value and reference types, with the former being the slim
> kind of values that OCaml has (without unique IDs), regaining your
> performance at the cost of adding unnecessary complexity to the core of the
> language.
>
I am not defending the use of <, > and consequently the use of internal
IDs, nor speculate on the effects this may have on language and/or
performance, but... it could be very helpful especially for a "debug
only" mode where such information is useful. In Java for example we have
such an ID available, and its not limited only to debug info (unless of
course we overload the toString() method).
> Then you get into passing semantics: are thing passed by value or by
> reference, or by value reference or reference to reference. I just discovered
> this hideousness in C# and it really brings home why OCaml/F# are so much
> easier to use.
>
Strange, I had assumed the addition of such an ID would not alter this.
In fact for a recent experiment I did I explicitly added an ID to the
type just to be able to output the data-structure via Graphviz/Dot for
debugging.
> For the one rare case that you want a unique ID on a bunch of values, it is
> definitely not worth sacrificing the simplicity of argument passing in all
> other cases!!!
>
__._,_.___
.
__,_._,___
|
[1-8]
|
|