Closed ffaf1 closed 2 years ago
Indeed, there is currently no nice way to do it in the API. We used to provide a Traversable
instance but that was pretty broken. For example, decorating a tree overlay (vertex 'a') (vertex 'a')
would give you overlay (vertex (1,'a')) (vertex (2,'a'))
, which is most likely not what you want. This is why we dropped the instance.
I don't see anything better than just coming up with a unique labelling f :: a -> Int
and then calling gmap f
.
Is that acceptable for your use case?
Thanks Andrey, so some sort of hash
function; that would do.
I would like my ID
s to be contiguous, but I guess that could be rectified by having getting the list of unique IDs, zipping it with [1..]
and running gmap
again.
Yes, although you don't have to go through the intermediate state with hashes. You could zip the deduplicated list of vertices with [1..]
, create a map from the resulting list of pairs, and pass that map's lookup function to gmap
.
I admit it's pretty fiddly and it would be nice to have something in the API that would make this sort of transform easier to make.
Ah, indeed that is smarter! Thanks again.
Il 08 aprile 2022 alle 04:19 Andrey Mokhov ha scritto:
Yes, although you don't have to go through the intermediate state with hashes. You could zip the deduplicated list of vertices with
[1..]
, create a map from the resulting list of pairs, and pass that map's lookup function togmap
.I admit it's pretty fiddly and it would be nice to have something in the API that would make this sort of transform easier to make.
-- Reply to this email directly or view it on GitHub: https://github.com/snowleopard/alga/issues/288#issuecomment-1092756681 You are receiving this because you modified the open/close state.
Message ID: @.***>
Hello. My goal is pretty simple: I have a
Graph a
and I would like to decorate each graph with a unique label, to end up with — say —,Graph (Int, a)
.If I were to do this on
Tree
s I would use atraversable
instance or similar, but I seeGraph
has no such instance. What is the correct way to approach this?