hash-graph icon indicating copy to clipboard operation
hash-graph copied to clipboard

Implementing transpose: are Head and Tail difference necessary ?

Open nobrakal opened this issue 7 years ago • 0 comments

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 transpose is reasonable ?
  • Does the difference between Head and Tail is deeper than just cosmetic ^^ ?

nobrakal avatar Jul 16 '18 15:07 nobrakal