Skip to content

Instantly share code, notes, and snippets.

@adithyaov
Last active July 22, 2019 19:38
Show Gist options
  • Save adithyaov/bf3bf5d595bc1bb587d0aea03f1b3412 to your computer and use it in GitHub Desktop.
Save adithyaov/bf3bf5d595bc1bb587d0aea03f1b3412 to your computer and use it in GitHub Desktop.
Implementation with shrink
module Acyclic.AdjacencyMap where
import qualified AdjacencyMap as AM
newtype AdjacencyMap a = AAM {
-- Unexported
underlying :: AM.AdjacencyMap a
}
instance Show (AdjacencyMap a) where
show (AAM x) = show . shrink $ x
fromAcyclic :: AdjacencyMap a -> AM.AdjacencyMap a
fromAcyclic (AAM x) = shrink x
vertex = coerce AM.vertex
edge = coerce AM.edge
instance Num (AdjacencyMap a) where
(AAM x) + (AAM y) = AAM (x + y)
(AAM x) * (AAM y) = AAM (x * y)
topSort (AAM am) = Typed.topSort . Typed.fromAdjacencyMap . fromAcyclic $ am
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment