-- | simplifyPath path, elminiating . and .. components (if possible)
simplifyPath :: FilePath -> FilePath
simplifyPath = joinPath . simp [] . splitDirectories
  where
    simp    ys        []  = reverse ys
    simp    ys  ( ".":xs) = simp    ys  xs
    simp (y:ys) ("..":xs)
          | y /= ".."     = simp    ys  xs
    simp    ys  (   x:xs) = simp (x:ys) xs

-- | A version of `catch` that catches `IOException`, and hence any exception
-- at all.
simplifyPath :: FilePath -> FilePath
simplifyPath = joinPath . simp [] . splitDirectories
  where
    simp    ys        []  = reverse ys
    simp    ys  ( ".":xs) = simp    ys  xs
    simp (y:ys) ("..":xs)
          | y /= ".."     = simp    ys  xs
    simp    ys  (   x:xs) = simp (x:ys) xs

-- | A version of `catch` that catches `IOException`, and hence any exception
-- at all.
simplifyPath = joinPath . simp [] . splitDirectories
  where
    simp    ys        []  = reverse ys
    simp    ys  ( ".":xs) = simp    ys  xs
    simp (y:ys) ("..":xs)
          | y /= ".."     = simp    ys  xs
    simp    ys  (   x:xs) = simp (x:ys) xs

-- | A version of `catch` that catches `IOException`, and hence any exception
-- at all.