From: <ch...@dt...> - 2004-07-05 12:14:44
|
Hi. It's always nice to hear from someone is interested in HaskellDB.=20 I'll try to answer your questions as well as I can. As you may or may=20 not know, I am one of the HaskellDB developers. I am also an=20 undergraduate student starting my 4th year this autumn. Adrian Hudnott wrote: >Hi. I'm new to Haskell but am exploring the >possibilities for extending the functionality of >functional programming languages in for my >undergraduate 3rd year project. Along with graphical >user interfaces databases seems one area where >functional languages are typically less developed than >imperative languages. While reading C J Date's >classic book I was inspired by the example of Datalog >applied to logic programming to think about similar >correspondences between relational databases and >functional programming, and realize that such >correlations are strong. I=92m looking to build a >pre-compiler and database access extension for a >mainstream functional language, based upon relational >algebra and the essence of types, tuples, etc. as >opposed to an SQL wrapper. Then I came across >HaskellDB and realized that this has already been >done! I also dug out some old papers which >integrate the functional paradigm and databases even >closer, such as FDM/DAPLEX (Shipman, 1981) and FQL >(Buneman, 1979). In a nutshell: Buneman reduces all >database queries into terms of functional composition, >mapping, filtering and tuple building without loosing >much clarity! There appear to be three possibilities >for where I could go from here: > >1)Do you (the developers, including Dr Leijen) have >any particular applications which you=92d like to see >HaskellDB put to use for? Perhaps one of these will >inspire me to head off in a different direction. > =20 > I'm not sure Dr Leijen reads this mailing list, so you might want to=20 contact him directly if you wish for his opinion. There are of course=20 lots of applications that could be created using HaskellDB. Most of them=20 involve combining HaskellDB and some other Haskell library. I am=20 currently developing a combined HaskellDB/wxHaskell program (a rather=20 dull GUI program that needs to access a database). Some of my colleagues=20 made a basic web forum by combining HaskellDB and WASH/CGI. >=20 >2)Investigate the possibilities for taking the >HaskellDB project further in some way. > =20 > There is some interesting work to be done here, that we have been=20 thinking about, specifically we want to add a non-SQL backend to=20 HaskellDB, perhaps something like Hardbms (nice since it is defined=20 completely in Haskell) The problem with this is that it requires lots of=20 internal restructuring of HaskellDB, which might prove too difficult (or=20 rather, time-consuming) for someone not familiar with the code. This is=20 something that's on the top of my list for future developments I want to = do. >3)The most ambitious and my favourite option: To >start from scratch at implementing something based >upon >similar principles to HaskellDB in NJ >SML/MLj/Java/JDBC or SML.NET/J# and javacc or SML >(which is much more the domain of my existing skills >set). My supervisor has some reservations, and asks >how much HaskellDB relies on laziness, in determining >whether this is practical? The documentation on >HaskellDB seems a little sparse (with me being new to >Haskell syntax as well!). How are you modelling the >=93dynamism=94 of a database? Meaning: when [say] an >insert operation is performed do you return =93a new >database=94? If so, what happens if you try to >perform an operation using a variable which still >points to =93the old database=94? > =20 > This sounds quite interesting, although it does seem like a rather large=20 project. I agree that the HaskellDB documentation is lacking, especially=20 for beginners. I recommend the following resources, in order: - Daan's and Erik Meijer's original paper, see=20 http://www.cs.uu.nl/people/daan/download/papers/dsec.ps - Daan's PhD thesis, chapter 5 talks about HaskellDB, see2 http://www.cs.uu.nl/people/daan/download/papers/phd-thesis.pdf - Our as of yet unpublished paper, found at=20 http://haskelldb.sourceforge.net/haskelldb.ps HaskellDB actually doesn't rely on laziness very much. It handles=20 dynamism through a Haskell concept called monads. I won't discuss them=20 further here. If you're not familiar with them, for now you may think of=20 them as a way to allow us to perform I/O in a purely functional way. I'm going to try and explain with some examples from my own program. A database is normally modeled with a function of type: db :: (Database -> IO a) -> IO a db =3D genericConnect "sqlite" ["./database","ReadWriteMode"] So here "db" is my database function. It takes another function as an=20 argument. It then uses this function to perform some action in the real=20 world, returning that result. It is used in the following way: addCustomer :: Customer -> IO () addCustomer c =3D db ( \db -> insert db C.customer (C.iD << constant (cid c) # C.name << constant (cname c) # C.address << constant (caddr c) # C.price << constant (cpric c))) Here our database is applied to the insert function. What this actually=20 does is that db connects to the database and performs the actions=20 specified, then disconnects and returns the result (which here is=20 irrelevant). getCustomers :: IO [Customer] getCustomers =3D db ( \db -> do t <- query db (table C.customer) return (map toCustomer t)) Here is another example. This queries the database for all our=20 customers, applies a Haskell function to them via map, and returns the=20 result of that operation. I hope this cleared things up a bit. >(P.S: I haven=92t actually managed to get a working copy >of HaskellDB installed yet. GHC compiles under >Mandrake but fails to work. HSQL - both Windows >binary and compiling from sources under Cygwin both >fail to work. :( ) > =20 > Too bad. If you provide me with some more information I might be able to=20 help you with this. Regards, Anders |