toRe :: Graph -> Int -> Int -> RE
toRe g start end = go start end (length g)
    where direct i j = filter (\x-> from x == i && to x == j) g
          go i j 0 = if i == j then Plus Epsilon s else s
            where s = foldl (\acc x -> Plus acc $ Single (label x)) Empty (direct i j)
          go i j k = Plus (go i j (k-1)) (Concat (Concat (go i k (k-1)) (Closure (go k k (k-1)))) (go k j (k-1)))
toRe :: Graph -> Int -> Int -> RE
toRe g start end = go start end (length g)
    where direct i j = filter (\x-> from x == i && to x == j) g
          go i j 0 = if i == j then Plus Epsilon s else s
            where s = foldl (\acc x -> Plus acc $ Single (label x)) Empty (direct i j)
          go i j k = Plus (go i j (k-1)) (Concat (Concat (go i k (k-1)) (Closure (go k k (k-1)))) (go k j (k-1)))
toRe g start end = go start end (length g)
    where direct i j = filter (\x-> from x == i && to x == j) g
          go i j 0 = if i == j then Plus Epsilon s else s
            where s = foldl (\acc x -> Plus acc $ Single (label x)) Empty (direct i j)
          go i j k = Plus (go i j (k-1)) (Concat (Concat (go i k (k-1)) (Closure (go k k (k-1)))) (go k j (k-1)))