[Haskell-cafe] File path programme
robdockins at fastmail.fm
Thu Jan 27 09:12:28 EST 2005
> Warning: I'm not interested in a path parsing/combining library, so my
> criticisms are perhaps unrelated to your goals.
> One thing that I'd be interested in seeing for any Path class would be a
> simple instance for FilePath (or String, if you want to imagine FilePath
> will be changed). Not everyone will want the overhead of a massively
> heavyweight Path datatype.
I'm not convinced that this is massively heavyweight, but your criticism
is heard. Perhaps we should realize that there are two separate things
going on here. One is the ability to pass around path names as black
boxes to the various IO routines without examining the path. The other
is the ability to examine and manipulate the path. So perhaps we want
something like this:
class PathStorage p where
fromBytes :: Int -> Ptr () -> IO p
withBytes :: p -> (Ptr () -> IO a) -> IO a
class (Show p,PathStorage p) => Path p where
path manipulation routines....
path parsing routines...
Then we could have things like:
instance PathStorage (Ptr ()) where
fromBytes _ ptr = return ptr
withBytes p f = f p
instance PathStorage (ForeignPtr ()) where
fromBytes _ ptr = newForeignPtr finalizerFree ptr
withBytes p f = withForeignPtr p f
instance (Storable p) => PathStorage [p]
fromBytes n ptr = peekArray n (castPtr ptr)
withBytes p f = withArray p f
as well as the full ADT implementations.
More information about the Haskell-Cafe