transpose
January 18th, 2009Real World Haskell, Exercise 4, p. 84:
Write a program that transposes the text in a file. For instance, it should convert “hello\nworld\n” to “hw\neo\nlr\nll\nod\n”.
Read the rest of this entry »
Real World Haskell, Exercise 4, p. 84:
Write a program that transposes the text in a file. For instance, it should convert “hello\nworld\n” to “hw\neo\nlr\nll\nod\n”.
Read the rest of this entry »
Let’s see if this worked. If you don’t see a caption it worked:
2008 was a year I moved to a new state on the other side of the country, and a part of that state I’d only been to once before. It also featured trips to China and Louisiana. The net result was one of the biggest years I’ve had in a long time. According to eBird, my year total was somewhere over 300 species. I don’t know exactly because I don’t enter the China data there. Even more impressively, 2008 saw 61 life birds, 12 from China, 3 from Louisiana, and 46 from California. That’s not even counting some new exotics like this Red-whiskered Bulbul from Huntington Library and Gardens:
Suppose the voters of this state passed a ballot resolution banning marriage between doctors and lawyers, and further invalidating existing marriages between doctors and lawyers. Would such a resolution be binding, or would it rightly be rejected by the courts? Are there any limits on the power of a ballot resolution beyond those set by the Federal Constitution?
I finished 2008 with 156 BGBY species, well behind the 200+ Neil Gilbert racked up in the same county, and he’s not as well situated as I am. In my defense I didn’t start until February, and was also dealing with a move to a new state. I didn’t even get my bike repaired from damage the movers did to it until April, and I lost a couple of weeks in the middle of Spring migration on a trip to China. With some effort, this year I might be able to crack 200.
However doing that is going to take some work. In particular:
Read the rest of this entry »
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:
:
to insert an item at the beginning of a list.++
to join two lists together.splitAt
.:
to prepend the new item to the second list.++
Am I missing something obvious here?