[Haskell-cafe] FGL problem: cannot acces data constructor NodeMap
Ivan Lazar Miljenovic
ivan.miljenovic at gmail.com
Sat Jul 24 09:30:30 EDT 2010
Once again cc-ing -cafe; Immanuel, can you please do "reply to all"
rather than just "reply" in GMail? :p
Immanuel Normann <immanuel.normann at googlemail.com> writes:
> 2010/7/24 Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com>
>
>> CC-ing haskell-cafe again:
>>
>> Immanuel Normann <immanuel.normann at googlemail.com> writes:
>>
>> > 2010/7/24 Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com>
>>
>> > Some of my lnodes in the graph have by construction unique labels and I
>> want
>> > to lookup the lnode from a graph given only the label of that lnode.
>>
>> Well, from my understanding NodeMap doesn't do what you want, since it
>> assumes that _all_ of the node labels are unique
>
>
> I wouldn't bother when NodeMap maps also non-unique labels to single nodes,
> because I only lookup nodes with unique labels, e.g. assume my label are of
> the form
> data Label = Unique String | Multi Label
I'm of the suspicion that using NodeMaps in this fashion will have
problem when considering nodes with the same label (even if you don't
explicitly use it for those nodes), as NodeMap seems to assume that node
labels are unique.
For example, mkNode assumes node labels are unique.
>> Furthemore, the way of using it seems to be analogous of how one would use a
>> State monad
>> rather than for actual interactive use throughout.
>>
>
> Could you elaborate this further, please.
http://hackage.haskell.org/packages/archive/fgl/5.4.2.3/doc/html/Data-Graph-Inductive-NodeMap.html#v%3Arun
and
http://hackage.haskell.org/packages/archive/fgl/5.4.2.3/doc/html/Data-Graph-Inductive-NodeMap.html#v%3Arun_
If you just want a mapping from labels to nodes, you may be better off
using your own custom Map (and maybe even defining a new graph type that
has such a Map as part of it).
The successor to FGL-5.x (whatever we'll end up calling it) will allow
you to have custom node types rather than using Ints. However, this
will not work for you in this situation.
The node type is just an _index_ type, analogous to the actual hash
value in a hash{map,array} (as opposed to the value which has the
hashing function applied upon it). It's there to provide a unique
identifier for a particular node. Arguably, an abstract type would be
even better as an Int as it will prevent you from doing silly things
like adding node indices together, but that's beside the point.
If you wish to find a node with a specific label, try using something
like gsel: http://hackage.haskell.org/packages/archive/fgl/5.4.2.3/doc/html/Data-Graph-Inductive-Basic.html#v%3Agsel
--
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com
More information about the Haskell-Cafe
mailing list