OK, so I took the advice of some of the commenters on my last post and tried using Haskell for creating developer tools at work. I needed a simple tool to extract certain info out of a database and store in some files. So, I first had to get a database library installed and working, to connect to the MS SQL Server database. Here is how I got on:
I found I then had to:
- Get hdbc
- Get hdbc-odbc
- Install the Microsoft MDAC SDK
- Compile the hdbc and hdbc-odbc packages
The READMEs in the former were quite helpful, but didn't really go all the way, and it took me a while to do everything. Here are my reflections on the whole process:
No tutorial style help for either doing this installation, or how to use the library. The docs that do exist for HDBC are fairly straightforward though.
So I want to create a connection. HDBC docs say:
A Connection object is created by specific functions in the module for an individual database. That is, the connect function -- which creates this object -- is not standardized through the HDBC interface.
So you would expect some ODBC specific docs. The readme for hdbc-odbc just says look at the hdbc docs, which don't have the information. I had to browse the ODBC source to find the the connectODBC function. Thankfully it wasn't too hard to work out.
I feel like I'm the first person to do this. I know I'm not from mailing list messages I've read, but it's scary, and it feels like no-one else cares enough to write a tutorial for this kind of thing.
I get crashes (well, out of memory really, but it amounts to the same thing) whenever I try to do anything with query results that involve an MSSQL 'ntext' field.
GHC's heap exhausted: current limit is 268435456 bytes; Use the '-M<size>' option to increase the total heap size.
This is a blocker for me. Bummer. I wasted about 4 hours on this dead end.
Where do I report bugs? Where are the mailing lists? Where is the 'KNOWN BUGS' list - or have I discovered the only known bug? I'll e-mail the author listed in the copyright, but it would be more reassuring if there was some website I could browse.
The documentation problem reflects the documentation for Haskell itself -- very variable. There are big gaps in Haskell documentation. For example, record syntax - the Tour of Haskell syntax doesn't even mention records. The Haskell wikibook is much better on this, but it's hard to find. The Haskell wiki page for Haskell keywords has lots of entries which are still just 'TODO'. There are several attempts to create comprehensive references, but none are complete, so you have to look through them all, and they are not always easy to find.
- Compilation just worked, once I'd got it set up, and using in ghci worked perfect, no further messing around with paths or anything was required.
- Haskell people know how to write APIs. The only ones I had to learn to get some values from my DB were 'connectODBC' and 'quickQuery'. That is just great, and compares favourably to every other DB API I've had to learn. The OO C# version I ended up having to write was much more verbose and clunky (though much quicker to write, as I knew what I was doing, and everything was already installed etc.)
- I managed to get some actual SQL queries working from the ghci interactice prompt within a pretty short period of time, which was very nice.
So it didn't work out, but I don't think it was a complete waste - I made some progress, and was impressed at how easy it was to get data out of a database, especially for a language where I/O was seen as an embarassing problem for so long (on the wiki page I wrote you can see how little code is actually required). Also, knowing open source developers like this, I imagine I might get my bug fixed very quickly.
However, there are serious issues if I really wanted to use Haskell for development tools on Windows. The problem is that all the other developers already have compilers, libraries etc for .NET and C#, and not much else. Installation would need to be tons easier before I could get away with writing tools in Haskell. Under Linux these things would have been much easier, as I could have just put together a few debs and been done, but installation of software is such a hassle in Windows.