Newbie Design Question
Brandon Michael Moore
Tue, 5 Aug 2003 11:25:33 -0700 (PDT)
On Tue, 5 Aug 2003, Thomas L. Bevan wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> I don't see that the contibutors files are fundementally different.
> - From what I understand, it should be possible to write a
> generic function,
> importCSV :: FilePath -> IO [ (String,String) ]
> where the 1st value is a field name and the 2nd the value extracted from
> the file.
The extracted fields and values should probably be grouped into records,
like [[(String,String)]], or [FiniteMap String String] (in GHC).
The read function should probably be paramaterized over a description of
the formats. Maybe there should be different read functions for differnent
families of files (fixed fields, comma delimited, XML, etc)
importFixed :: FixedFormat -> FilePath -> IO [[(String,String)]]
importComma :: CommaFormat -> FilePath -> IO [[(String,String)]]
importXML :: XMLFormat -> FilePath -> IO [[(String,String)]]
The *Format types are supposed to represent the exact format of the file.
For example, you might represent the usename examples as
[Field "First Name" 10,Field "Last Name" 10] (with a suitable Field type)
If the file descriptions are instances of Read they could easily be loaded
from files at runtime.
> As for the mapping to XML, I would suggest using HaXml and writing a
> set of functions that write the value for a field into the correct place.
> These could then be indexed in another tuple list of type,
> [(String, String -> CFilter)]
I think the idea here is that the functions take a string and produce a
filter that will transform the xml represntation of a record by adding
that field. If that is the intent of the type, I think the filters might
be fairly complicated, but it should deal nicely with missing fields.
Another approach would be to use DTD translation and the writeXML class.
The DTD2Haskell tool will produce a data type that might be more
convenient to work with than building your XML with generic combinators.
> Then draw it all together with a liberal use of map and fold.
> On Mon, 4 Aug 2003 10:05 pm, Tanton Gibbs wrote:
> > Haskellers,
> > I'm currently working on my first Haskell program. I really like the
> > language so far, though it has been hard to break the OO frame of mind.
> > Normally, I'm a C++/Perl programmer, but I have really enjoyed the
> > type-safety of Haskell over Perl as well as the Hugs interpreter over a
> > make cycle. Since execution time is not important, I haven't found any
> > issues with using Hugs.
> > Now, on to my problem. Our company uses XML to describe our processes.
> > I'm writing a DSL in Haskell that will print that XML out. I've done most
> > of it, but now I'm describing the I/O in the XML. Basically, we have files
> > come in in various formats from various file contributors and we use a
> > mapping program to map the fields to the right spots in the XML. So, for
> > example, one contributor could have the following layout:
> > Field Name Start Pos Length
> > First Name, 1, 10
> > Last Name, 11, 10
> > and another contributor could have them in exactly the opposite order.
> > Furthermore, some contributors may have fields that others don't (for
> > example: DOB).
> > I'm now trying to come up with a way to map this information into Haskell
> > dynamically. It would be trivial to create a module for each Contributor
> > and then import all the modules. However, we have hundreds of contributors
> > and it would be a pain to have to change and re-release the program every
> > time we added a new contributor. Therefore, I need someway to take this
> > information and map it into my Haskell structures. I have come up with two
> > options. One would be to let Haskell dynamically import a contributor
> > module (but I don't think that is currently possible); the other would be
> > to use a configuration file and have the user specify the information
> > through it. Is there a standard Config file module? Is there any other
> > way to do this that I missed?
> > Thanks in advance,
> > Tanton Gibbs, Ph.D.
> > Technical Architect
> > Abilitec Knowledge Base
> > Acxiom Corporation
> > Conway, AR 72034
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe@haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.2 (GNU/Linux)
> -----END PGP SIGNATURE-----
> Haskell-Cafe mailing list