« August 2005 | Main | October 2005 »

September 29, 2005

1 more for the road!

The last two nights I’ve been playing around with Erlang. I kinda of like it. The standard documentation supplied with erlang seems incredibly well written for a technical subject. The “Getting Started” guide got me picking up the language fairly quickly. I’m almost through the sequential programming chapter. Next is concurrent programming and I’m looking forward to that (I’ve cheated and looked ahead). I must have reached some tipping point with functional programming languages. It’s getting easier and easier for me to pick them up. I keep seeing the same concepts repeated over and over again, albeit with dissimilar syntax and semantics.

September 27, 2005

two camls diverged in a ...

It turns out that Ocaml is a fairly simple language to learn. Very few keywords (let, type, match and function being the main ones) and the standard assortment of data structures (list, array, tuple, record). I think the best quick introduction to the language is Ocaml For Scientist Chapter 1 combined with Ocaml for Experienced Programmers. Overall I was impressed with Ocaml. Although it sells itself as a functional programming language, the language does have imperative constructs (when you absolutely positively need a for loop). It also has a good number of libraries available online (Ocaml can also use CPAN, yes CPAN! as in perl. Perl4Caml. I haven't tried it though YMMV). Between Haskell and Ocaml, Haskell definitely felt like the more challenging of the two languages to learn. I would still start with Haskell if I did it over again. But definitely learn both languages!

September 26, 2005

1 step forward, 2 step backwards

Link: dating advice for men from women | MetaFilter.

Sometimes I wonder how the human race has managed to procreate.

September 24, 2005

guess what this ad is for?

Here's to the Crazy Ones.
The misfits.
The rebels.
The troublemakers.
The round pegs in the square holes.
The ones who see things differently.

They're not fond of rules.
And they have no respect for the status quo.

You can praise them, disagree with them, quote them,
disbelieve them, glorify or vilify them.
About the only thing that you can't do, is ignore them.

Because they change things.

They invent. They imagine. They heal.
They explore. They create. They inspire.
They push the human race forward.

Maybe they have to be crazy.

How else can you stare at an empty canvas and see a work of art?
Or, sit in silence and hear a song that hasn't been written?
Or, gaze at a red planet and see a laboratory on wheels?

We make tools for these kinds of people.

While some may see them as the crazy ones, we see genius.

Because the ones who are crazy enough to think that they can change the world,

are the ones who do.

View this ad here.

September 23, 2005

This myth is busted!

Link: Encyclopedia: MythBusters Episodes.

I love this show. It's one of the cooler shows on TV right now.
Did I mention I saw Jamie Hyneman when I was in San Francisco? E had to help me contain my excitement. IT WAS SO FRIGGING COOL! Probably the most interesting thing that happened to me while I was down there.

See I told you slashdot was useful!

A nifty little trick I learned while reading slashdot.

Picture 1

September 22, 2005

Oh Haskell! I can see you too

Link: Visual Haskell.

When I said Haskell felt more academic.... Forget what I said. I fully expect the Haskell Enterprise Edition out any day now. It'll probably have a cheesy quote to go along with it like: "Haskell - The purely lazily strongly statically typed choice for the monadic enterprise".

It's 1 am. Do you know where your sleep is?

I’m still up. I should have been Zzzzing 2 hours ago.

a little camel said to me, "are you being objective?"

1. Write a function merge_i which takes as input two integer lists sorted in increasing order and returns a new sorted list containing the elements of the first two.

This is one of the exercises in chapter 2 of Developing Applications with Objective Caml. Took me a little while since I don't use a lot of recursion in my day job. On my first pass, I nailed the base case but the recursive case I messed up. I discovered this handy little trick when using the interpreter.

Objective Caml version 3.08.3

# use "test.ml"
val merge_i : int list -> int list -> int list = <fun>
# #trace merge_i;;
merge_i is now traced.
# merge_i [1;2] [3;4];;
merge_i <-- [1; 2]
merge_i --> <fun>
merge_i* <-- [3; 4]
merge_i <-- [2]
merge_i --> <fun>
merge_i* <-- [3; 4]
merge_i <-- []
merge_i --> <fun>
merge_i* <-- [3; 4]
merge_i* --> [3; 4]
merge_i* --> [2; 3; 4]
merge_i* --> [1; 2; 3; 4]
- : int list = [1; 2; 3; 4]
#

Aha! Initiallly, I was only passing the tail of the two lists on the recursive call. I needed to modify it to pass the tail of the list which I had used and pass the other list untouched. That trace feature in the interpreter sure is handy (I believe lisp and ruby also have this in their REPL).

The solution came to this:

let rec merge_i (x:int list) (y:int list) =
    if x = [] && y = [] then []
    else if x = [] then y
    else if y = [] then x
    else let a = List.hd x
         and b = List.hd y
         in if a > b 
            then b :: merge_i x (List.tl y)
            else a :: merge_i (List.tl x) y  ;;

(* in the last else, I had done (if a > b then b else a) :: merge_i (List.tl x) (List.tl y) initially *)
(* the if x = [] && y = [] then [] is probably superfluous but it's late and I'm going to sleep *)

P.S (* *) is an OCaml comment. Very /* */ if you ask me.

I've wanted to learn this for awhile

Tried to learn this back in 2000-2001 but didn’t get very far. Ocaml has a lot of similarities to Haskell. The learning resources available on the web are better now (http://www.ocaml-tutorial.org is excellent). I also spent time looking at the ocaml website and the OReilly Ocaml book (available on line, google for it!) Conceptually similar, both are strong statically typed functional programming languages. I actually prefer the Ocaml syntax after mucking with it for awhile. Haskell has this idea of a layout which makes the program sensitive to indentation ala Python. It’s not so bad once you get used to it but I got bit by it when I started out with Haskell. Ocaml appears to be a more pragmatic, working language (it has imperative features, better libraries) where Haskell tends to be more academic (though Pugs and Darcs are written in Haskell). It’s worthwhile to learn both languages as each bends and twists your mind in different ways.