Last active
July 22, 2019 19:38
-
-
Save adithyaov/bf3bf5d595bc1bb587d0aea03f1b3412 to your computer and use it in GitHub Desktop.
Implementation with shrink
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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