Skip to content

Instantly share code, notes, and snippets.

@5outh
Created December 5, 2012 22:06

Revisions

  1. 5outh created this gist Dec 5, 2012.
    20 changes: 20 additions & 0 deletions Graph.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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