Category Archives: Technology

Why I Love Haskell In One Simple Example

I recently implemented some new Haskell numeric types that, instead of performing calculations, can generate a rendering of the requested calculation or store units with it.

Here you see a transcript of my session with a Haskell interpreter. The mathematical statements I am entering after the “>” are standard Haskell expressions, and, as I demonstrate, normally evaluate to a single result.

Once I get a more powerful simplifier, I will probably write a LaTeX exporting function as well.

The entire implementation of this, BTW, is less than 200 lines.

NumTest> 5 + 1 * 3
8
NumTest> prettyShow $ 5 + 1 * 3
"5+(1*3)"
NumTest> rpnShow $ 5 + 1 * 3
"5 1 3 * +"
NumTest> prettyShow $ 5 + 1 * 3
"5+(1*3)"
NumTest> prettyShow $ simplify $ 5 + 1 * 3
"5+3"
NumTest> prettyShow $ 5 * (Symbol "x") + 3
"(5*x)+3"
NumTest> 5 / 2
2.5
NumTest> (units 5 "m") / (units 2 "s")
2.5_m/s
NumTest> (units 5 "m") / 2
2.5_m
NumTest> 10 * (units 5 "m") / (units 2 "s")
25.0_m/s
NumTest> sin (pi/2)
1.0
NumTest> sin (units (pi/2) "rad")
1.0_1.0
NumTest> sin (units 90 "deg")
1.0_1.0
NumTest> (units 50 "m") * sin (units 90 "deg")
50.0_m
NumTest> ((units 50 "m") * sin (units 90 "deg")) :: Units (SymbolicManip Double)
50.0*sin(((2.0*pi)*90.0)/360.0)_m
NumTest> rpnShow $ dropUnits $ ((units 50 "m") * sin (units 90 "deg"))
"50.0 2.0 pi * 90.0 * 360.0 / sin *"
NumTest> (units (Symbol "x") "m") * sin (units 90 "deg")
x*sin(((2.0*pi)*90.0)/360.0)_m

Also, I defined this in my source file:

test :: forall a. (Num a) => a
test = 2 * 5 + 3

Now, it can be used:

NumTest> test
13
NumTest> rpnShow test
"2 5 * 3 +"
NumTest> prettyShow test
"(2*5)+3"
NumTest> test + 5
18
NumTest> prettyShow (test + 5)
"((2*5)+3)+5"
NumTest> rpnShow $ test + 5
"2 5 * 3 + 5 +"

You can grab the very early experimental code with darcs get http://darcs.complete.org/num.

Haskell has no built-in support for numeric types with units, arbitrary symbols carried through computations, etc. But it was trivial to add it. This kind of extensibility is a key part of why Haskell is so amazing.

Don’t Buy Albatron

My MythTV box has an Albatron KM18GPro motherboard in it. Last week, the Ethernet port on it went dead. I can plug in a known good cable, and don’t even get LED activity on the port. Plug the same cable into any number of other machines, and it works fine. (This is repeatable across different cables and switches, too.)

So I submitted an online RMA request to Albatron. Despite their claim of “instant confirmation” when an e-mail address is supplied, after submitting the form, it says to call them if there’s no response after 48 hours. I also submitted the proof of purchase as they requested.

Since there wasn’t, I called them and got a voice mail box. Left a voice mail. It was never returned. I also e-mailed their RMA team. No response. I’m sure this has nothing to do with the fact that my warranty expires in a few weeks.

It’s now been days since I first contacted them. This is absolutely the worst hardware support I’ve ever received from any vendor — taking days to even *respond* to a problem. I recently had a problem crop up with my Sipura SPA-841 phone, and got a replacement on its way to me within 12 hours. That’s right, a *phone* got better service than this motherboard.

I’ll never buy from Albatron again.

Their site says “Capturing the spirit of the albatross.” I think they got it wrong. It should be “capturing the spirit of the weasel.”

Brightness

I discovered by accident today that the scroll switch on the top of the unit will adjust the screen brightness in X. It doesn’t seem to work in the console, and I’ve done nothing to tell X about it, but it works. Woohoo.

Combined with that and laptop-mode and powernowd, I think I’m going to get 3 to 3.5 hours of battery life on this thing.

Unsolved Tablet Mysteries

Things I’m not sure how to do yet:

  1. Adjust the brightness of the tc1100 screen in Linux
  2. Display xvkbd (or another on-screen keyboard) when the display has been locked via xscreensaver or KDE’s screensaver
  3. Make sure the ACPI thermal settings are correct
  4. Find a journaling filesystem that behaves well with laptops

About the ACPI settings… it seems like the fan is running more than it ought to, and also that the unit is warmer than it should be at times. Out under (from memory) /proc/acpi/thermal/THRM, I can find the current temperature and also the temperatures at which different things (fans, I guess) are supposed to be turned on. Strange thing is, that file that shows the temperature zones shows different temperature zones at different times. Also, the /proc/acpi/fan area never says that any fan is on, even when I can hear them.

Odd.

On the filesystem front — back when ext2 was about as good as it got, I used to tweak the kernel cache flushing code so that writes would only be flushed to disk every 30 minutes or so. My laptop was plenty reliable, and it would always do a sync before I’d close the lid anyway, so that saved on the disk usage. But these days, I’m not so sure how to do that, with either ext3 or reiser4. Any suggestions?

Tablet PC So Far

As I mentioned earlier, I purchased an HP tc1100 tablet PC. It arrived earlier this week and I’ve been playing with it. Here are some of my initial impressions:

Debian stable (sarge) installed easily. The tc1100 has no optical drive, and I have no USB optical drive either. It also wouldn’t boot from a CF card in my USB card reader. So I did a PXE (network) boot. I had never known that Debian’s installer can boot over the network. VERY slick work, d-i team. During the installation, I noticed letter “Q” appearing on-screen periodically. I eventually determined that it would happen whenever I’d bump one of the mouse buttons. It also went away once I was using my own kernel, for whatever reason. The basic install was easy, no troubles at all. I was particularly impressed with the integration of ntfsresize these days. Being able to shrink down the XP partition to a very small size and then install Linux — very nice indeed.

There are lots of pages about the tc1100 under Linux, so I won’t rehash them all here. There are a few patches to the kernel to enable wireless support and the touchpad. All fairly straightforward. My unit uses the ipw2200 instead of the ipw2100 that everyone else seems to have, strangely enough.

The main thing I don’t have yet is suspend-to-memory (ACPI state S3). Standby (ACPI state S1) doesn’t have any noticable effect. With S3, the system will suspend, but crash on recovery. Can’t quite figure it out.

I did get hibernate (suspend-to-disk) working. I just have to shut down PCMCIA and unload the b44 Ethernet driver before engaging it, and then it’ll work fine. Not as nice as a true suspend, but still better than powering down all the time.

As far as apps go, the one that I really must mention so far is Jarnal. It’s an awesome program. At its simplest, it’s just a set of pages you can draw on on-screen. But there’s a lot more to it under the hood. First, it saves your work as a zipped set of SVG files, one per page. So you can load up your drawings into other programs later. Secondly, you can load up PDF files as the background, effectively letting you mark up documents and jot notes on them. Finally, there is a collaborative network mode that I haven’t even tried yet. Jarnal is GPL’d, but it requires Java 1.4.x. If if weren’t for that, I’d be uploading it to sid in a heartbeat.

I’ll keep posting as I have more thoughts.

Calculators

Many students need calculators, and I’m no exception, with my physics class this semester.

I got my HP 48GX calculator 10 or more years ago. For those of you not familiar with HP calculators, let me give you a bit of a background.

HP is a company that, for many years, had a dedicated calculator division. They produced many of the world’s most advanced calculators for science, engineering, and business. Their top-of-the-line series, the HP48 and HP49, contained some features that you’d normally have to pay hundreds or even thousands of dollars to get in PC applications. In many ways, the HP48/49 series were far more advanced than any other calculator, even most on the market today. Their ability to use both algebraic and stack-based (RPN) modes simultaneously is nice, too.

HP has pretty much killed off its calculator division, though. I don’t know why; I think they were profitable. Perhaps one of Carly’s many “strange” ideas.

Anyway, back to the story…

I recently pulled out my HP48GX, having not used it heavily for about 6 years. I found that I didn’t remember some things about it and went searching for the manuals. The manual that comes with the calculator is 600 pages, and the optional “advanced” guide is another 600 pages. I found that hpcalc.org has scans of the manuals — very nice. And when I say the 600-page book came with the calculator, I mean there was an actual book in the box. Not some 3-page booklet and a CD-ROM with a PDF.

After (literally) dusting off the HP48GX, I pressed the power button. Two surprises: 1) it turned on, and 2) it still had all my data and files from six years ago in memory. Sweet. I had written a few useful programs for the calculator (yes, it can be programmed in its own language, or C or assembler) and was glad to see them intact.
I also discovered a saved Chess game (of COURSE you can play chess on the HP48GX) on the unit.

So I thought — I better back this thing up. First task: find the serial link cable. Took awhile of rummaging through boxes, but there it was. Second task: find a Kermit or XModem program for Linux. (When’s the last time you’ve needed *that*? I’m betting it’s been awhile.) Third task: read the manual, because I forgot *how* to back up the calculator. So after a little while (9600bps, after all), I have a nice dump of the memory.

There are some people, myself included, that believe that the HP48G series was the best calculator HP ever made, and still one of the best available. By the time the HP49 arrived, HP had decided it needed to be “cheaper” to compete with TI. So it was built with lower-quality components. Also, HP wanted to compete with TI in the high school market, so it removed some of the more advanced (and useful) features, and added some geared for that market. Sigh.