I have a dynamically constructed file path in haskell that ends up something like this:
/abc/def/../ghi/./jkl
and I’d like to reduce it to the more readable
/abc/ghi/jkl
For printing. Is there a library function to do this in haskell? I’ve looked all over and can’t find one. It’s not too hard to write, but it’s a bit messy because you have to “look ahead” for “..”s, and I’d rather use a baked-in function if I can.
Beware that this is not simply a string processing question when links are involved:
So you need to do IO.
The nearest I can find to what you want is
canonicalizePathfromSystem.Directory. It returns a path starting from the root directory, so you may want to use it in conjunction withmakeRelative, also fromSystem.Directory. But it does run inIO.