[Haskell-cafe] How to give unique name/id to nodes outside any monad ?

minh thu noteed at gmail.com
Thu Jan 8 04:21:30 EST 2009

Nothing, simply the notation. Now, with the remark of Luke, I'm
wondering how bad it is to use makeStableName/hashStableName to "copy"
the data structure in a similar one with explicit reference (that is,
using pointer or keys in a map or whatever).

Thank you,

2009/1/8 Lennart Augustsson <lennart at augustsson.net>:
> Look at http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-StableName.html.
> But what's wrong with constructing the graph in a monad?
> On Thu, Jan 8, 2009 at 9:53 AM, minh thu <noteed at gmail.com> wrote:
>> Well, the processing of the data structure has to be done in the IO monad.
>> What is the library you talk about ? Could it give the "stable names"
>> (in IO) for
>> each node of the mentioned graph (I mean, after the graph has been constructed
>> purely) ?
>> Thanks,
>> Thu
>> 2009/1/8 Lennart Augustsson <lennart at augustsson.net>:
>>> Of course you don't need a monad, but you need to do the same
>>> operations as you would with a state monad to number the nodes.  This
>>> is the only way in (pure) Haskell.  There is no object identity in
>>> Haskell, so if you want the nodes to have identity you need to provide
>>> it.
>>> GHC does have a library for stable names which (in the IO monad)
>>> allows you to get something akin to the address of a value in memory.
>>> But that's not the functional way of doing this.
>>>  -- Lennart
>>> On Thu, Jan 8, 2009 at 9:28 AM, minh thu <noteed at gmail.com> wrote:
>>>> Hi,
>>>> I'd like to process some kind of graph data structure,
>>>> say something like
>>>> data DS = A [DS] | B DS DS | C.
>>>> but I want to be able to discover any sharing.
>>>> Thus, in
>>>> b = B a a where a = A [C],
>>>> if I want to malloc a similar data structure,
>>>> I have to handle to the node representing B
>>>> two times the same pointer (the one returned
>>>> after allocating A [C]).
>>>> To discover sharing, I thought it would be
>>>> necessary to give unique name to node and
>>>> then compare them while traversing the graph.
>>>> I could give the name by hand but it would be
>>>> cumbersome. But at least it would not require
>>>> any monad for the bookkeeping of ungiven
>>>> names. Is it possible to give those names
>>>> automatically but outside any monad ?
>>>> Thanks,
>>>> Thu
>>>> _______________________________________________
>>>> Haskell-Cafe mailing list
>>>> Haskell-Cafe at haskell.org
>>>> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list