Skip to content

Instantly share code, notes, and snippets.

@5outh
Created December 5, 2012 22:06
Graph
module Graph(
Graph(Graph),
removeEdge,
outbound,
inbound
)where
data Graph a = Graph{ vertices :: [a], edges :: [(a, a)] } deriving Show
removeEdge :: (Eq a) => (a, a) -> Graph a -> Graph a
removeEdge x (Graph v e) = Graph v (filter (/=x) e)
connections :: (Eq a) => ((a, a) -> a) -> a -> Graph a -> [(a, a)]
connections f x (Graph _ e) = filter ((==x) . f) e
--outbound connections
outbound a = connections fst a
--inbound connections
inbound a = connections snd a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment