[Haskell-cafe] File path programme
Graham Klyne
GK at ninebynine.org
Mon Jan 24 11:20:23 EST 2005
At 15:17 20/01/05 -0500, Mark Carroll wrote:
>I tried writing a little command-line utility to find the relative path of
>one thing from another thing (with Unix-like systems in mind). ...
FWIW, there's logic to do something like this in my URI module [1]. Bear
in mind that there is not, in general, a unique solution (e.g. in extremis,
the absolute path of the target might be a legitimate solution, regardless
of the base).
[1] http://www.ninebynine.org/Software/HaskellUtils/Network/URI.hs
There's also a slightly later copy in the Haskell libraries CVS, which I
believe is due to ship with the next GHC release. Look for function
relativeFrom.
See also module URITest.hs [2], for examples of relative paths created by
this algorithm (look for function testRelSplit).
[2] http://www.ninebynine.org/Software/HaskellUtils/Network/URITest.hs
#g
--
At 15:17 20/01/05 -0500, Mark Carroll wrote:
>I tried writing a little command-line utility to find the relative path of
>one thing from another thing (with Unix-like systems in mind). For example,
>
>$ ./pathfromof /etc/init.d/ /etc/X11/XF86Config-4
>../X11/XF86Config-4
>$ ./pathfromof /tmp/baz/ /tmp/foo/
>.
>$ ls -l /tmp/baz
>lrwxr-xr-x 1 markc markc 8 2005-01-20 12:01 /tmp/baz -> /tmp/foo
>
>It turned out surprisingly complex, though, and doesn't feel very neat or
>tidy at all, nor is it very portable given that I couldn't find generic
>library functions for manipulating bits of filepaths. Anyhow, it's at
>http://www.chiark.greenend.org.uk/~markc/PathFromOf.hs and may yet have
>egregious bugs.
>
>It seems to me like it could certainly be improved in various ways. If
>anyone has any thoughts, as to how I could improve my style, make more use
>of standard libraries, etc., I'd certainly appreciate them.
>
>Thanks,
> Mark
>_______________________________________________
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
>http://www.haskell.org/mailman/listinfo/haskell-cafe
------------
Graham Klyne
For email:
http://www.ninebynine.org/#Contact
More information about the Haskell-Cafe
mailing list