[Haskell-cafe] Re: How to give unique name/id to nodes outside any
monad ?
Ertugrul Soeylemez
es at ertes.de
Thu Jan 8 07:13:40 EST 2009
"minh thu" <noteed at gmail.com> wrote:
> 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).
Probably you're misusing the notation. I don't see any reason, why
monadic notation should be less readable. Usually it's even more
readable. Luke's remark is very valid. Haskell is the wrong language
for imperative programming. You don't have _any_ benefit of Haskell, if
you use it like C. Try to change your mind. Monads aren't evil. They
are there to make your life easier. Way easier than imperative methods.
Greets,
Ertugrul.
> Thank you,
> Thu
>
> 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
> >>>>
> >>>
> >>
> >
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/
More information about the Haskell-Cafe
mailing list