Monday, March 22, 2010

Grrrr...

Grrrr... not much to report.

I've wondered in the past if Haskell might make a good language for writing data compilers: something to take source art and turn it into something ready to be linked into the game. My thinking was that it would allow for concise construction of parsers, good error messages when input is ill-formed, and make it easy to morph the data through multiple representations in the compile process.

I needed some vector art for my lunar lander program and thought I'd just take SVG output from Inkscape and convert it to a triangle mesh for inclusion in my game. Seems simple enough. I don't know yet what the best way to represent graph structures like triangle meshes will be in Haskell, but I can probably dodge that for now.

Step 1: Install Haskell. There is an installer called the Haskell Platform which is supposed to be a one-step install for everything you need. On Windows it really hasn't been well thought out though. It installs to the Program Files (x86) directory by default, but Microsoft really wants this directory to be read-only apart from installation, which seems to break the Haskell package-manager's assumptions about what it can do. If you try to install to a different directory it doesn't respect that. Some things go to the directory you've specified but most things land back in Program Files (x86). Very unprofessional!

Step 2: Parse SVG. SVG is an XML format. There are five or six different XML parsers in Haskell with no clear indication of which one's “the one you should be using”. I have a book that uses HaXml so I look it up. It doesn't appear to be installed, even though it's part of the standard Haskell libraries. I run the cabal package manager to install it. Can't do it unless I elevate privileges to Administrator first. OK, that works. But on the web I see there's another one called the Haskell XML Toolkit; it claims to be better than HaXml. So I try installing it. It fails trying to install the curl library. After searching around on the web I find a thread from November 2008 describing what's wrong: the curl library installer depends on running a shell script of some sort, and on having the curl C library installed! So you need Cygwin installed. Once Cygwin is required you've lost me; sorry!

I'll try this out in Python next. I have a feeling it will be ridiculously easy.

3 comments:

Mark said...

Your Haskell story sounds like every experience I've ever had with open source software in my entire life.

I implemented an SVG reader for my 2D vector game, but it's pretty trivial -- just a bunch of hacky C++ that digs around in the SVG file for the actual drawing instructions and then records a tiny subset of the most popular ones.

Leandro Penz said...

I've tried at least one of the libraries for parsing XML in haskell. Well, I didn't like it either.

In the end, I used a custom Parsec parser. When someone says that Haskell is good for parsing, they are usually refering to Parsec, with good reason.

JP said...

Well, this is the sad story of GHC under Windows I saw as well. Under Linux, everything works like charm. I don't know whether the MS Windows is the unwanted child in the Haskell community, but I rather play with Haskell over ssh on one of my Linux boxes than use GHC directly on my XP netbook. I don't mind too much anyway.

Maybe you could write a post on reddit haskell if you are still interested.