You are viewing [info]elbeno's journal

 

Elbeno

About Recent Entries

I'm syndicated Jul. 28th, 2007 @ 09:18 pm
Add elbenoblog to your friends list to get my distal wibblings in your friends page. Thanks to [info]greatbiggary.

Bye LJ Jul. 28th, 2007 @ 12:01 am
Hello Wordpress.

This journal has moved. I've had enough of LJ - increasingly it's looking like last century's tech in terms of what I need. I'll keep the free account just to aggregate my friends pages. So I'll still be commenting on your LJs!

From now on, you can find me at www.elbeno.com/blog. I'm sure Wordpress will have its foibles, but at least I'll be able to do something about them. I won't be on your LJ friends pages any more. You can figure your own solution to reading/aggregating my blog, if you still want to.

Sgt Pepper Mashup Jul. 27th, 2007 @ 11:08 am
This is great. "Lucy at the River" is particularly inspired, I thought (also mirrored).

Thinking about ditching LJ Jul. 25th, 2007 @ 11:29 pm
And moving to Wordpress. I already have hosting. LJ isn't too reliable, actually, and it's not nearly as flexible as Wordpress would be. So... if I switch, I could still access friends pages here, but LJ denizens wouldn't get me in their auto-aggregated friends pages.

Harry Potter and the Deathly Hallows Jul. 21st, 2007 @ 11:55 pm
I've just finished it, so I can now return to the Internet. Sorry for the delay - I'm in a late timezone to start with, and had to look after mini-Elbeno this morning.
Other entries
» Bye Bye Internet
Apparently scans of Harry Potter and the Deathly Hallows have been leaked to Bittorrent. So I'm boycotting the Internet until I've read it.
» More on Tree Folds
After some thought, I think I have the definitions for left and right fold on a tree:
foldrTree :: (a -> b -> b) -> b -> InternalTree a -> b
foldrTree f z ILeaf = z
foldrTree f z (IBranch a x y) = foldrTree f (f a (foldrTree f z y)) x

foldlTree :: (a -> b -> a) -> a -> InternalTree b -> a
foldlTree f z ILeaf = z
foldlTree f z (IBranch a x y) = foldlTree f (f (foldlTree f z x) a) y

Of course, these folds are simplified: they don't have a separate function for dealing with leaves and branches. This leads to things like flatten only working one way, i.e.
foldrTree (:) [] t
works because (:) will accumulate values onto a list properly from the right, but
foldlTree (:) [] t
gives a type error (because (:) cannot append a value onto a list working from the left).
» Arboreal Haskell
(Chapter 7 of The Haskell School of Expression is about trees.)

The first definition is of a tree with values stored only at the leaves, i.e.

data Tree a = Leaf a | Branch (Tree a) (Tree a)

It then gives a mapTree function (equivalent to map on a list), which is trivial, and functions fringe, treeSize and treeHeight, which return respectively the list of the leaf values, the number of leaves, and the max depth. In the text, these are defined in the usual recursive way. An exercise is to write a Tree equivalent of the fold function for lists. Which I think I managed:
foldTree :: (a -> b -> b) -> (b -> b -> b) -> b -> Tree a -> b
foldTree fLeaf _ init (Leaf x) = fLeaf x init
foldTree fLeaf fBranch init (Branch x y) = fBranch x' y'
    where x' = foldTree fLeaf fBranch init x
          y' = foldTree fLeaf fBranch init y

The trick was in recognising that I needed two functions, one for dealing with leaves and the other for dealing with branches (because (:) is a different type from (++) and both are used in fringe). Of course, the performance implication of all those list appends makes me think that in the real world, I'd write fringe using only (:):
fastFringe :: Tree a -> [a]
fastFringe t = acc t []
    where acc (Leaf x) l = x : l
          acc (Branch x y) l = acc x (acc y l)

(It also occurs to me that fringe is more usually called flatten IME). The next exercises involved trees with internal values (not at the leaves), i.e.
data InternalTree a = ILeaf
                    | IBranch a (InternalTree a) (InternalTree a)

This is a bit more like way I'm used to trees working, and the exercises were easier. InternalTree versions of zipWith and zip (defined in terms of zipWith of course) were easy, as were versions of take and takeWhile. I was impressed with the "magic" of the InternalTree version of repeat:
repeatInternalTree :: a -> InternalTree a
repeatInternalTree a = t
    where t = (IBranch a (t) (t))

There are two bits of magic here. First, this is an infinitely recursive definition. Haskell uses lazy evaluation, so this is designed to be used with takeTree or takeTreeWhile. The second piece of magic: where is the base case constructor (ILeaf) specified? It isn't! Yet

takeTree 2 (repeatInternalTree 5)

returns

IBranch 5 (IBranch 5 ILeaf ILeaf) (IBranch 5 ILeaf ILeaf)

as hoped for, if not quite expected. The only thing I'm not really grokking right now are the InternalTree versions of foldr and possibly foldl (and possibly a third type of fold). I've got a feeling there is some higher-order function extractable that controls pre-, post-, or in-order node traversal on InternalTree, but I'm unsure of the structural differences of foldl and foldr when applied to trees. I am also puzzling a bit over the semantics of zipWith and zip when applied to trees with only leaf-node values.

PS. Gleep = glorp.
» Book Sale Haul
Today was the quarterly book sale at the Culver City library. The haul:
  • 16 Hardy Boys books
  • The Past Through Tomorrow - Robert A Heinlein
  • River Out of Eden - Richard Dawkins
  • Operating Systems Design and Implementation - Andrew Tanenbaum
  • The Design of the Unix Operating System - Maurice Bach
  • Introduction to Automata Theory, Languages and Computation - Hopcroft & Ullman
  • Mathematics for Dynamic Modeling - Edward Beltrami
  • Introduction to Parallel Computing: Design and Analysis of Algorithms - Kumar, Grama, Gupta & Karypis

» Harry Potter and the Order of the Phoenix
Probably the best of the lot so far, even though it did cut a lot from the book. Mind you, the book had a lot of cuttable stuff, so that's not a bad thing. The film stuck to the plot well. A criticism perhaps is that the adult characters weren't really explored much, and perhaps it suffered from there being a bit too much that had to be cut out. Daniel, Rupert and Emma have really matured as actors. Other notable turns, I thought, were Evanna Lynch as Luna Lovegood and Helena Bonham Carter as Bellatrix Lestrange.

Also, The Golden Compass (Philip Pullman tie-in due out around Xmas) looks like one to watch out for.
Top of Page Powered by LiveJournal.com