Tag haskell (9)
Posted on 2008-02-14 10:13:00
Tags: haskell programming politics links
Appropriately, the ban on selling sex toys in Texas was overturned (although it doesn't take effect until March). I swear, the laws we pass in this state. I wonder if there's a count somewhere of which state has had the most laws overturned by a federal court?
I think my stomachache yesterday was caused by the large mocha (four shots of espresso!) I had in the morning to try to curb my headache. Then I wasn't hungry for lunch, then I was very hungry for dinner. Anyway, that's all sorted out, and my head is doing significantly better. I slept much better than I thought I would. Hooray!
From this article about Clinton campaigning in Texas:
Delia Guajardo, 63, a retired administrative secretary, was among several in the crowd who said they don't foresee Obama swaying them: "Just the Obama name scares me. It's not a common name."Seriously? Seriously?? Maybe that's why Kucinich never wins the primary?
Haskell wearing me down
Posted on 2007-08-15 10:57:00
Tags: math haskell projects
but first, math!
From last time - the answer is that they're not symmetric. If a=10, b=11, c=20, then C enters A's stall at time 10 and you get to enter B's stall at time 11. However, if a=20, b=11, c=10, then C enters B's stall at time 11 and you have to hold it until time 20. More formally, the time you have to wait is
min(min(a,b) + c, max(a,b))
Using the formulas min(a,b) = (a+b-|a-b|)/2 and max(a,b) = (a+b+|a-b|)/2, this expression simplifies down to (a+b+c-|c-|a-b||)/2, which is clearly not symmetric in a and c. I'd be interested to see how this formula works for more people and stalls - it seems to blow up pretty quickly, although it would be easy to write a program to calculate it. I have a gut feeling that you want the fastest people earlier in the line (ideally if there are n stalls the n-1 slowest people will be all in their stalls when you get to go in, so you don't have to wait for them) but proving that seems rather tricky.
When will LJ get inline LaTeX?? :-)
Good article about risk management and terrorism (via schneier)
I'm making good progress rewriting the Pretty Pictures picture generator in Haskell - it spits out valid PPM images that look correct for simple cases, but it needs more testing. (and I need to see if browsers support PPM natively or if I have to convert to PNG which would be a pain) I'm not enjoying it a whole lot, though. The idea of learning Haskell was to expand my mind and change the way I programmed, and I guess it has done that some, but I always feel handcuffed when I sit down and try to do seemingly easy things, like write out a raw PNG file. (got about halfway there and said forget it)
To antidote this (yes, it's a verb!) I think my next project will be less challenging technically and more interesting, like involving lots of neat data (census? past wars?) and some sort of neat visualization. (R?) We'll see.
Happy Fifth of July!
Music: Radiohead - "Where I End and You Begin"
Posted on 2007-07-05 13:03:00
Tags: microresolution haskell worldofwarcraft links
Yesterday was nice - we got djedi his flying epic mount, finished Super Paper Mario, went out to eat at Copeland's, and didn't let the stormy weather get us down!
Super Paper Mario - pretty good game, and the story was kind of interesting, but not nearly as interesting as the ridiculous amount of conversation, etc. that you have to go through. Still enjoyed it though.
As previously mentioned, we saw Transformers at Bengies. I've only been to a drive-in once before, so it was fun! The place is pretty nice and retro, although the owner seems to be one of those people that sees it fit to enumerate every single thing you shouldn't do. See the House Rules and FAQ for examples. There was a condom machine in the bathroom that had (not exaggerating here) four paragraphs about how the management doesn't endorse their usage, and how it's just there for protection and abstinence is the only sure protection, etc. Yikes. The movie was pretty good for a summer blockbuster. (read: lots of giant robots fighting) I've never seen the series on TV so maybe you'd get more out of it if you did?
Microresolution complete! I spent some time on the hat puzzle genetic algorithm thing in Haskell. It's frustrating to work on because I really have to get in the functional state of mind, but I wrote a few tough methods (randomly selecting which genes to reproduce based on the fitness function) so I feel good about that. The genetic part of this is going to end up being a sort of framework for writing genetic algorithms in Haskell, which is a neat side benefit (although such things already exist).
I'm trying out Twitter. It seems neatish.
In Ohio, you can't get arrested on the Fourth of July! (except for felonies and treason...you would think the penalty for committing treason on the Fourth of July would be more strict or something :-) )
Babies learn to lie when they're six months old - lousy lying babies!
Posted on 2007-07-02 11:11:00
Tags: movies microresolution haskell computer
For our anniversary, we ate at Famous Dave's BBQ and saw Ratatouille. Famous Dave's - not bad, but the meat was kind of fatty. And no, their brisket wasn't "as good as anything you'll find in the Lone Star State", as their menu audaciously claimed. Ratatouille - excellent, excellent, excellent (same director as The Incredibles!). Very sweet comedy. Made me hungry. kottke's review convinced me to see it.
After a little bit of pain, I got my new hard drive set up, SATA and all, and all the data copied over. It's even faster than the old one! I'm experiencing some weird freezes (usually if I wait 10-15 seconds it will come back) in WoW, but I think it may be a video driver problem; I just upgraded them so I'll try downgrading tonight or tomorrow.
Microresolution: I will spend at least one hour of concentrated time before the end of Saturday on the Haskell version of the hat puzzle. (writing the genetic algorithm) I've been trying to do this for a while but I always find myself distracted by other things. I don't know why it's so important to me to do this, but it is.
Posted on 2007-03-29 15:41:00
Tags: haskell congressvotes
Allergies seem to be on the retreat, thanks to a little extra sleep today and tons of tea and orange juice and hot chocolate.
I should have worked on congressvotes yesterday, but I didn't have the activation energy. The problem is that parsing the XML and extracting any sort of data gets really really really slow - like 37 minutes to do a little bit of stuff to all 600ish votes from 2006. I've looked at the code and I can't find anything in particular that's inefficient about it, but I'm pretty new at Haskell. The next strategy is to do an offline transform to some sort of friendlier text format with just the information I need, and hopefully the web service, etc. can just use those text files. Hopefully I'll give this a shot sometime soon. (for some reason this post about premature optimization spoke to me; it's a good general philosophy!)
Wow, are there really going to be Kwik-E-Marts? I could go for some Krusty-O's...
Extortion is profitable!
Posted on 2007-03-22 08:55:00
Tags: haskell congressvotes
Man, I feel productive! (not in a work sense, but in a doing stuff at home sense) Last night I wrote the LJ-Blog adapter for fairydust1 - as she mentioned, all of the posts on her blog will become friends-only posts on the account boltonblog, so friend it if you haven't already! It only took a couple of hours (partially because I had code from ljbackup for interacting with LJ, and partially because I backed off a little from my goal and just posted the summary text from the RSS feed here ), and I was happy I could knock it out and it seems to work. (and sorry for the flood of posts, but I was even more afraid as I went to bed that it would keep doing that every hour!)
I also made some more progress on my congress votes project. Learned how to download files in Haskell - as with anything involving IO, it's a little tricky and I haven't quite got the hang of it yet, but I managed to make it work. The next hard part is figuring out which votes are "important" and which aren't from the Reason on the bill, such as "On Motion to Suspend the Rules and Pass, as Amended", "On Motion to Recommit with Instructions", "On Agreeing to the Amendment", etc. Some of these I'm going to have to ignore if they deal with amendments because that information is hard to find. And I need to make sure voting "Yea" means voting for the bill and not against it!
Episcopal Bishops in U.S. Defy Anglican Communion - it's really nice to see the leaders of your church say this:
We proclaim the Gospel that in Christ all God's children, including gay and lesbian persons, are full and equal participants in the life of Christ's Church.
new project: congress ratings
Posted on 2007-03-19 18:48:00
Tags: haskell projects programming congressvotes
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
What does Thursday mean to you?
Posted on 2007-03-15 07:55:00
Tags: haskell worldofwarcraft tivo programming
It hit 70 degrees here yesterday! It was absolutely beautiful. Of course, it's going to be cold again tomorrow, but it was nice to have a touch of spring.
I finished and posted my latest WoW guild data project. It was fun, but nothing too tricky about it.
So I read about the Amazon Unbox downloads on the TiVo, so I signed up. (free $15 if you link the accounts by the end of April!) We rented A Scanner Darkly to try it out (you have to watch it within 30 days, and once you watch it it expires in 24 hours), and it downloaded in like an hour. Very very cool stuff. It's also neat because if you buy something, Amazon saves it and you can redownload it at any time. (except if the stupid copyright holder doesn't let you, grr) Also, they have a small number of TV series including 24, Firefly, and Arrested Development.
My attempt at comprehending Haskell continues. I read through A Gentle Introduction to Haskell which, despite the title, is not really gentle at all. I'm also looking through the Haskell Wikibook which is a little too slow-paced for me, but it's a nice change of pace after the other one! I'm starting to get some of the ideas, and remembering why functional languages are so cool. As a crazy example, you can do something like
y = x * 2
x = 2
and it will still work, since variables are only assigned to once, so I guess it can figure out the order things should run in. (I should note that I can't find the reference for this anymore, so it may not be true. Also, this seems like a crazy thing to do in a functional language anyway.) Maybe my next Haskell project will be to write a bot for WoW! (*)
I've gotten in to work at 7:45 every day this week, surprisingly enough. I've also been to the gym every day.
I got two nice "Congratulations!" cards in the mail from my relatives for my engagement. Yay!
(*) - Just kidding. My next project won't be WoW-related. Also, this is borderline crazy to try to do.
Posted on 2007-03-14 08:09:00
Tags: haskell programming
So it's been a little while since I've learned a new language, and I keep hearing rumblings about Haskell (programming.reddit.com really loves it). So I started to read A Gentle Introduction to Haskell, and...wow. I haven't done deep functional stuff since college, and I made it about halfway through before my brain up and revolted.
It has a lot of neat features that you would expect in a functional language, and it has the neat Prologish way of defining functions by pattern matching. For example, here's my first Haskell program!
leng  = 0
leng (_:xs) = 1 + leng xs
main = print (leng ['a','b','c'])
This is defining a function leng ("length" is built in to the standard library) that returns the length of a list. Note that you don't say what to do to calculate the length, exactly, you specify that the length of an empty list is 0, and the length of any other list is 1 plus the length of the rest of the list.
It took me a while to figure out the exact syntax to define this, but I finally did and compiled it with the Glasgow Haskell Compiler (ghc). It took 6 seconds, which seems like a really long time for something so simple. Maybe there's a fixed amount of overhead or something. And the resulting executable was 370KB!! I'm guessing this is because it compiles it to a binary executable, which I wasn't expecting, so you don't get the benefit of an interpreter. It runs instantly, as you would expect.
Anyway, I'll keep reading and thinking what would be a good project to do in it. I/O looked weird, but that was about when my brain shut down yesterday so maybe I'll start there today...
This backup was done by LJBackup.