hash-graph
hash-graph copied to clipboard
Implementing transpose: are Head and Tail difference necessary ?
Hi,
I am trying to implement transpose (the function that invert all the edges of the graph) for my benchmarks.
I made:
transpose :: Gr () Int -> Gr () Int
transpose (Gr g) = Gr $ M.map (\(Context' h t) -> Context' (Set.map (\(Tail a b) -> Head a b) t) (Set.map (\(Head a b) -> Tail a b) h)) g
Basically, I am inverting heads and tails. But because there is a type difference between an Head and a Tail, I must convert them (and thus map into the two sets).
But:
data Head a b = Head !a !b deriving (Eq, Generic, Show)
data Tail a b = Tail !a !b deriving (Eq, Generic, Show)
They look very similar.
So two questions:
- Does my implementation of
transposeis reasonable ? - Does the difference between
HeadandTailis deeper than just cosmetic ^^ ?