I need to build a function that returns all paths between specific nodes.
connect :: Int -> Int-> [[(Int,Int)]]
The Data.Graph library gives me a useful buildG function that builds a graph for me. If i call
let g = buildG (1,5) [(1,2),(2,3),(3,4),(4,5),(2,5)] ,
I will get an array where each node maps to neighbors. Example:
g!1 = [2] g!2 = [3,5] .. g!5 = []
I tried to do this using lists, but I'm not very good at haskell, and I am getting an input error that I cannot fix.
connect xyg | x == y = [] | otherwise = [(x,z) | z <- (g!x), connect zyg]
I do not need to worry about cycles at this point. Here is what I want to get:
connect 1 5 g = [[(1,2),(2,3),(3,4),(4,5)],[(1,2),(2,5)]]