[Haskell-cafe] File path programme

Simon Marlow simonmar at microsoft.com
Wed Jan 26 09:51:10 EST 2005


On 26 January 2005 14:30, Malcolm Wallace wrote:

> Keean Schupke <k.schupke at imperial.ac.uk> writes:
> 
>>> So let's define a new algebraic datatype something like:
>> 
>> I think you can guess what comming - why not use a class for
>> extensibility:     class Path p where ... The path class would
>> provide all the operations for using paths... 
> 
> Yup, good idea, and I think this would also allow David Roundy's
> suggestion of a FastString implementation of filepaths - it becomes
> just another instance.
> 
>> This has the advantage that people can add instances for platforms
>> without having to alter the code in the library...
> 
> Exactly.  Yes.

Hmm, I deliberately didn't suggest using a type class.  Do you really
want to expose Win32 paths and POSIX paths, and whatever else, as
different types?  Maybe you do for extensibility, but you really want a
single Path type too - otherwise portable code will have to use
conditional compilation.  The Path type therefore has to be an
existential wrapper:

data Path = (CPath p) => Path p

Maybe we do want to do this, but it causes portability issues with the
Path library itself: nhc98 can't compile this code for example - you can
rewrite it using an explicit record of operations, as long as none of
the operations are polymorphic...

Cheers,
	Simon


More information about the Libraries mailing list