But what's wrong with constructing the graph in a monad?
On Thu, Jan 8, 2009 at 9:53 AM, minh thu <noteed@xxxxxxxxx> 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) ?
> 2009/1/8 Lennart Augustsson <lennart@xxxxxxxxxxxxxx>:
>> 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
>> 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@xxxxxxxxx> wrote:
>>> 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 ?
>>> Haskell-Cafe mailing list
Haskell-Cafe mailing list