Haskell: Concatenation vs. Prepending

Wednesday, January 14th, 2009

This confused me a little until I grokked it. In Haskell, an item is not the same as a list containing the one item. (Obvious, I know, but some languages like XQuery take the opposite view).

The : operator prepends an item to the beginning of a list. It can only be used to insert an item at the beginning of a list. It cannot be used to append an item to the end of a list. Thus x:xs is correct but xs:x is a syntax error. (Haskell’s design seems stuck with assumptions going all the way back to Lisp and 1950s era processors including that the singly linked list is a good implementation for the list abstract data type. This has other consequences. For instance, length is an O(n) operation. And now that I look for it, insert into the middle of the list also seems to be missing.)

Lists are concatenated with the ++ operator, not :.

So, to sum up:

  • Use : to insert an item at the beginning of a list.
  • Use ++ to join two lists together.
  • To append an item to a list, insert the item into an empty list, and then concatenate the two lists together.
  • More generally, to insert an item into a list at any position other than the first:
    1. Split the list into two sublists at the insertion point with splitAt.
    2. Use : to prepend the new item to the second list.
    3. Concatenate the two lists back together with ++

Am I missing something obvious here?

How to Tell Where Eclipse Finds a Class?

Saturday, January 3rd, 2009

I’m debugging a weird class loading issue in XOM. Some of my unit tests can find the Crimson parser. Some can’t. I don’t know why. In Eclipse, I can press F3 and it locates both the class and corresponding source for this jar. But where did it find it? is there any way to see where (i.e. path in the file system) that class came from?

Big Finish for a BGBY Year

Thursday, January 1st, 2009

I had New Year’s Eve off so I decided to see if I could add a few final birds to my BGBY list. I could have tried for the Northern Waterthrush at San Joaquin or a possible Yellow-throated Vireo at Mason Park. However, those sites are just too familiar. I’ve been to each of them many, many times over the last year; and they hold few surprises any more. Instead I decided to get on my bike and head down to the beach; more specifically to Robert E. Badham, where a lot of the rocky shorebirds and pelagic birds hang out. I hadn’t yet been out to the shore on my Bigby travels this year, and thus there were at least two guaranteed new BGBY birds on almost any trip–Heermann’s Gull and Brandt’s Cormorant–and another dozen or so were possible. so I pumped up my bike tires, packed my scope and a lunch in my backpack, and took off down the Mountains to Sea trail.

The morning was incredibly foggy, not the best climate for viewing birds. Plus high tide was coming at Badham about 10:00 AM and low tide at 4:30 AM. On any other day, I would have called it off, and gone back to Mason or San Joaquin; but this was really now or never for the beach in 2009. When I started I could hear a few birds but visibility was severely restricted. I was very glad that most of the trip would be on bike paths and very low traffic roads since I wasn’t sure cars could see me. I could hear some Yellow-rumped Warblers, a Crow or two, and just barely make out a couple of Mallards in San Diego Creek. I heard Canada Geese honking long before I saw them fly down the creek. I hoped the fog would lift quickly, but by the time I reached Upper Newport Bay, it was still thick on the ground:

Fog, ducks, and bridge

I could make out the American Coots in the water, a few Lesser Scaup, a noticeable group of Redheads, and a few shorebirds including a Long-billed Curlew and a Spotted Sandpiper. However, I didn’t even bother pulling my scope out of my backpack since I couldn’t see far enough to need it anyway. Searching for the Loggerhead Shrike or Short-eared owl would have been hopeless. Sidenote: Willet calls from out of the fog are really eerie.
(more…)

2009 New Year’s Resolution

Thursday, January 1st, 2009

I finally pushed Jaxen 1.1.2 out the door, and my resolution (singular) for 2008 is to finally finish XOM 1.2 as well. Then maybe, just maybe, I’ll have a little room to take on one more hobby project this year, but what should it be? They’re a few ideas I’m kicking around, and I’m wondering which would b the most interesting/lucrative/fun. Here are a few ideas:

1. GPS tracking software for Android

The screen on my Garmin handheld unit cracked two days after I got an unlocked Android phone to play with. Coincidence or fate? Some folks are already working on Android GPS apps. Maybe I could contribute to their efforts.

In fact, far and away the major feature I use on my Garmin eTrex is simple measurement of how far I’ve walked, along with occasional downloads of paths. I wouldn’t have to reimplement the entire Garmin stack for the Android, just the one or two pieces I actually use.
(more…)

G1 First Impressions

Wednesday, December 31st, 2008

So now I’ve had a little time to play with my G1 phone, and my initial impression is that it shows promise, but isn’t fully usable yet. In particular,
(more…)

Google Stole My Menu Bar

Tuesday, December 30th, 2008

I knew there was something bugging me about Chrome, but I just couldn’t put my finger on it. I finally realized what it is: There’s no menu bar!

Chrome Browser Window with no menu bar
(more…)