Posts on March 19, 2007

new project: congress ratings
Mood: excited
Posted on 2007-03-19 18:48:00
Tags: haskell projects programming congressvotes
Words: 421

So my next project is fun and neat. I can't remember how exactly I got here, but I noticed that all roll-call votes in congress are accessable in a handy XML format (Here's an example vote - note that the page you see is that XML file after being processed with an XSLT stylesheet, so you'll have to hit View Source to see the raw data). My idea (a little vague at this point) is to take all of the votes, and then figure out which issues I care about and which way I would have voted, and then "rate" representatives as to how closely their votes align with mine. This is a little grand in scope.

Anyway, it took me a while to get HaXml (a Haskell XML parser) installed, because I kept not being able to compile it from source for various stupid reasons. Anyway, I finally figured out that it was in fact in Debian in the libghc6-haxml-dev package, which made my life about 5 times easier.

So I saved a sample vote and have it parsing and I'm extracting simple data from it, which is exciting! I have a few questions, though: does anyone know the answer to these?

- I have these two functions:

nothing :: Maybe a -> Bool
nothing Nothing = True
nothing (Just _) = False

findElementContent :: String -> Content -> Maybe Element
findElementContent target (CElem el) = findElement target el
findElementContent target _ = Nothing

findElementContents :: String -> [Content] -> Maybe Element
findElementContents _ [] = Nothing
findElementContents target (c:cs) = if (nothing (findElementContent target c))
then findElementContents target cs
else findElementContent target c

findElementContent takes in a target tag and some data (Content), and returns the element that has that tag name if it exists, and Nothing otherwise. (findElementContents is just a helper function to do the same thing with a list of Content) But findElementContents looks pretty ugly to me - what I want it to do is return findElementContent target c if that isn't Nothing, and otherwise recur on the rest of the list. The code is correct, but is it inefficient since I'm calling findElementContent target c twice? My limited understanding says no, since findElementContent is referentially transparent since it doesn't use monads (i.e. if you call it again with the same inputs it will return the same thing, always), but I'm not entirely clear on this.

- As I mentioned, findElementContents seems a little inelegant - is there a better way to do this? Is there some builtin nothing that I couldn't find?

Resources I've been using:
- HaXml reference
- standard library reference, including the Prelude

2 comments

back to the grindstone
Mood: confused
Posted on 2007-03-19 14:16:00
Tags: movies
Words: 221

So destroyerj came up and visited this weekend, and lo, it was fun! (except for the whole flight being cancelled Friday because of snow/sleet here) We went to DC on Saturday and saw the National Cathedral for the first time. Unfortunately, it isn't near a Metro stop so we walked .75 miles there and .75 miles back. (apparently there are buses that go there from some stops, but the walk wasn't too bad) It's a very pretty and awe-inspiring place; I took some pictures (that we later viewed on the Wii Photo Channel!) that turned out pretty well that I hope to put up before the end of the week. (wow, apparently there's a Darth Vader sculpture there, although hidden by construction; thanks, Wikipedia!)

We watched A Scanner Darkly on the TiVo that we had rented from Amazon Unbox. All in all, the unbox -> tivo thing worked beautifully, and I'd definitely do it again. (especially since we have $11 in credit left!) The movie itself was good - the rotoscoping really added to the "unreality" of the whole movie, in addition to looking really really cool (particularly the scramble suits, which rotate through faces and clothing)

I started my next project which will indeed be in Haskell. I'll save the details for when I'm at home and can properly ask my questions.

0 comments

This backup was done by LJBackup.