[Haskell-cafe] File path programme

Keean Schupke k.schupke at imperial.ac.uk
Wed Jan 26 09:22:25 EST 2005


Malcolm Wallace wrote:

>So let's define a new algebraic datatype something like:
>
>    data Path   = Unix  { absolute   :: Bool
>                        , dirnames   :: [String]
>                        , basename   :: String
>                        , extensions :: [String]
>                        }
>                | DOS   { absolute   :: Bool
>                        , drive      :: Maybe Char
>                        , dirnames   :: [String]
>                        , basename   :: String  -- max 8 Chars
>                        , extension  :: String  -- max 3 Chars
>                        }
>        --      | Win32 ...
>        --      | MacOSClassic  ....
>        --      | VMS | CPM | Amiga | ARM ....
>
>  
>
I think you can guess what comming - why not use a class for extensibility:

    class Path p where ...

Then different types for each platform:

data UnixPath = UnixPath ...

which would be made instance of the Path class... The path class would 
provide all
the operations for using paths...

This has the advantage that people can add instances for platforms 
without having to
alter the code in the library...

    Keean


More information about the Libraries mailing list