Wednesday, April 29, 2009

Getting started with OCaml

A friend with some experience with SML asked me how to get started with OCaml, so I thought I'd write this incomplete guide.

Apparently, the internet also has a "Getting started with OCaml" guide. My guide will remain competitive by being much more concise (and therefore, incomplete).

Steps to getting started:
  1. Download an OCaml compiler from somewhere. Other useful things to have are ocamlfind (which finds your OCaml libraries), ocamllex (for lexing), and ocamlyacc (for parsing). Another useful thing is OCamlMakefile, which helps you manage builds with Make.
  2. Read a tutorial or two. This is a good thing to read. Also, bookmark the Index of modules.
  3. Write some programs while compiling frequently. (Compiling too late in the game may cause death of the Ocaml experience.)
  4. If you want to lex and parse, look into ocamllex and ocamlyacc.
Some details:
  • OCaml is very similar to SML. The only different parts are loops and things like that. I try to stay away from those because they are creepy.
  • The file extension is .ml; the file extension for interfaces is .mli. You don't need an interface file; without one you export everything by default.
  • The contents of file somefile.ml are in the Somefile namespace, which you can open with "open Somefile." By default all of these little guys are exposed. You can hide things by creating modules and writing module interfaces. Read more about that here.

Some important things to know:
  • OCaml is the future because (arguably) a lot of people are using it. It is the new big thing for scientific computing because you can actually get good performance out of it!!
  • OCaml is more practical than Haskell for some things and also yields better performance more easily.
  • One thing OCaml is not great for is backwards compatibility. Each new release of OCaml supposedly breaks a lot of things. From my understanding a lot of libraries change/break, causing everyone to experience organ failure.
How I learned OCaml:
  1. In fall of 2006, I spent a long time struggling with the MLton SMLNJ compiler. It gave me lots of obscure errors and I cried.
  2. From fall of 2006 to spring of 2007, I came to not only be master* of the MLton compiler but also the Moscow ML compiler. These compilers are not only difficult to use but also often difficult to install, so you should be very impressed.
  3. After learning SMLNJ was not really being maintained anymore, I said "screw this shit" and moved on to Haskell.
  4. In January of 2009, I realized** that OCaml is the future. For my next project I decided to use OCaml, which I picked up in an ad hoc ways throgh the steps above, skipping step 2 (but compiling very frequently). I am still in this step.
* This is subjective.
** Through a combination of talking to people about what people used for different things, trying to do 3D arrays in Haskell, and meeting myself at Xavier Leroy.

Speaking out

I was wandering around Boston when I came across the following poem on the Holocaust Memorial:

When the Nazis came for the communists,
I remained silent;
I was not a communist.

Then they locked up the social democrats,
I remained silent;
I was not a social democrat.

Then they came for the trade unionists,
I did not speak out;
I was not a trade unionist.

Then they came for the Jews,
I did not speak out;
I was not a Jew.

When they came for me,
there was no one left to speak out for me.

This poem, which is by Pastor Martin Niemoller about the inactivity of the German intellectuals to speak up after the Nazi rise to power, made me think about the importance of standing up for people who are not in a position to speak out for themselves. Big picture-wise, the most relevant example these days is immigrants, illegal and otherwise (non-U.S. citizens), who do not have the full rights and freedoms of citizens and have been treated increasingly worse in the last few years. On a smaller scale, there are many opportunities day-to-day to speak out: from the stories I hear many workplaces are rife with subtle (and not-so-subtle) racism, sexism, and general inappropriateness. The perpetrators may not mean harm, but as we learned in sensitivity training at Google, the intent does not matter--only the oucome. (Also, I personally don't find racism or sexism very funny. Do you?) We should be aware and conscientous that we are not going along with things just because we are comfortable members of a majority.

Monday, April 27, 2009

Exercise videos aren't so bad...

First yoga, now exercise videos*?! It started when I wanted to begin doing more stretching outside of yoga class. I picked up Rodney Yee's A.M. Yoga DVD while browsing at Whole Foods, which contains five 20-minute workouts, one for each morning: standing poses, twists, forward bends, backward bends, and hip openers. I was so inspired by my enjoyment of this practice that today I picked up Bollywood Booty, a dance workout to lift (??) and tone one's backside, and Rodney Yee's Back Care Yoga. The first one was much more fun than the back care yoga, which was yoga at a much slower pace than I was used to and involves a chair as a prop. (It seems to basically take the strengthening parts out of various poses that stretch the back and make it so that you don't have to work much to stretch your back.) These videos provide a nice alternative for doing nothing on nights when I come home after the gym is closed. I never thought I'd say this, but exercise videos aren't so bad.

* I would like to note that these videos are a supplement rather than a substitute for my normal workouts. For instance, today I did the two videos after I'd gone for a 4-mile run earlier.

Thursday, April 23, 2009

Someone who is honest about PL design

Gilad Bracha on how he was a computational theologist with the job of interpreting (programming) language specifications. :)

The Narcissism Epidemic

In this Newsweek article, writer Raina Kelley mentions a new book, The Narcissism Epidemic, and reflects on how societal forces have caused today's young people to become self-centered far beyond having healthy self-esteem. An issue I have with this article is that Newsweek seems to be using this article to appeal to narcissists looking to identify with other narcissists: 1) they include photographs of young people partying recklessly, looking in mirrors, etc. that don't portray the people in a negative way and 2) the writer seems to use the mention of the book as a jumping-off to discuss how her own life experiences have cured her of narcissism... (This may have just been a symptom of the fact that the article was not centered around a tight thesis.) Despite this, the article is worth reading because it brings up good points about how it is good for young people to be taught humility. Society should say "no" to us and give us grades lower than B's every once in a while.

Isn't it a good thing that even Newsweek recognizes that it is important to remind me that it's not all about me? ;)

Wednesday, April 15, 2009

Using the non-functional parts of OCaml is often creepy

I tried to use Map.iter a few times, but it was just creepy:
iter : (key -> 'a -> unit) -> 'a t -> unit

The function takes a function that takes a key, value, and updates some state, and then in the end you don't get anything back--just the updated state that lives somewhere else. Agh! I prefer to use Map.fold, which makes the state updating more explicit:
fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b

Monday, April 13, 2009

What will happen when tides turn?

China's gender gap is estimated to be 32 million: largely due to the one-child policy and selective abortion, there are 32 million more young males (under the age of 20) than young females. I can't imagine that the culture will continue to value baby boys for much longer. I once watched a documentary on the social unrest people fear resulting from a population of mostly young men, many of whom are unmarried with no change of marriage. When/how will this cause families to begin valuing baby girls? Will the scarcity of marriageable young women increase their societal value in healthy, productive ways or will it increase the degree to which women are objectified? Wjdk*.

* "We just don't know"--a phrase I borrow from my friend Joe Zimmerman.

Programming of the future

Interaction and search allow ambiguity, concision.

Nostalgia, or why I am not a creative writer

Senior Spring: bangs too long; drinking.*

* This flash blog post inspired by Six-Word Memoirs on Love and Heartbreak, which were inspired by by Ernest Hemingway's six-word flash fiction, "For sale: baby shoes, never worn."

Thursday, April 09, 2009

Downward dog, happy puppy

I had thought this was a joke, but it's true: dog yoga is the new big thing. I don't do yoga with the dog I don't have, so I am not sure how I feel about this.

Sunday, April 05, 2009

So many books, so little time

Below are some books I've recently finished, with some brief commentary:

Non-fiction

Unlocking the Clubhouse: Women in Computing
, by Jane Margolis and Allan Fisher - a well-researched, engaging 2001 book describing 1) surveys of the current state of the women in computer science (or lack thereof), 2) suggestions about how to improve the situation, and 3) descriptions of current efforts to increase numbers of women in CS and their results so far. Margolis and Fisher discuss how societal stereotypes of the "boy hacker" icon often cause women to have less exposure to and interest in computing. They provide well-motivated suggestions for how to change classroom dynamics, and recruiting efforts to include more women in computing. I am happy to say that many of the issues in this book are somewhat dated by now: since the publication of this book, the "locker room" classroom dynamic has become less acceptible now, and computing as a field has moved more towards applications and connections to other fields rather than being just about pure speed and power. My issues with the book are that 1) it does not motivate why more women should be in computing and 2) it does not portray women who do computer science favorably. While I clearly believe that more women should be in computing because it is useful and because women can be good at it, I would have liked to see the authors' reasons. As for the second point, the book portrays women in computer science as survivors victimized by bad classroom dynamics and inadequate support networks. The book quotes all these women either explaining why they chose to stick with computer science or saying things like "well, I took these courses and they were difficult, but I persevered." There is not a single confident woman in the book who is passionate about computer science. (Maybe they couldn't find one, but I don't think they looked tha hard. My female professors have all been confidant and passionate.) Also, much of the book addresses the "fact" that there are all these women who start out behind and lack the confidence to continue without much speculation on social factors for this--it becomes easy to read this as "women start out with a disadvantage because they are weaker." It might be for this reason that the book assumes women's self-reported levels of aptitude and experience are accurate and never discuss normalizing self-reported levels by actual performance. (It is a known phenomenon that women tend to deflate their abilities in surveys and men tend to inflate. There are studies on this and I have experienced this personally.)

Zelda, by Nancy Milford - a biography about F. Scott Fitzgerald's wife Zelda Sayre. Because of my teenage crush on This Side of Paradise's protagonist Amory Blaine, I had become very interested in the Fitzgeralds and what I thought was their exciting Jazz Age life and read all of Scott's books and also Zelda's large autobiographical novel Save Me the Waltz. From the fiction I had gathered that Scott was burdened by a very inspiring but crazy* wife; this books provides a sympathetic and surprising view into Zelda's life. Zelda not just inspired Scott, but he often included her letters and diary verbatim in his works. (The "broken columns and clasped hands and doves meant romances" line from Paradise is from one of Zelda's letters. Instead of acknowledging her he bought her a nice fan. WTF, Scott?) When Zelda received a publishing offer on her diaries, Scott refused, saying that they provided him a lot of material. When Zelda was writing Save me the Waltz, Scott tried to prevent it from being published and eventually had it taken off the shelves. Later, when Zelda was very ill and badly wanted to write novels, Scott told her she wasn't good enough and that she was allowed to do anything except write. The biography left me much less a fan of Fitzgerald than I used to be. However, if you are interested in the fiction based on the Scott-Zelda dynamic, a nice triology is Scott's Tender is the Night, Zelda's Save Me the Waltz, and Hemingway's Garden of Eden.

Fiction

My Mistress's Sparrow is Dead
, edited by Jeffrey Eugenides - the author of Middlesex has compiled an anthology of "love stories" that may be of a different nature than what one might first imagine a love story to be. These stories include classics like Faulkner's A Rose for Emily and Nabokov's Spring in Fialta. I also discovered some good comtemporary ones, such as Jon by George Saunders, about lust, love, and difficult decisions between two teenagers in a distopian world where they are part of the Trendsetters and Tastemakers, children chosen to detect and set trends by assessing products every day. Another good one is Lorrie Moore's How to be an Other Woman.

Mysteries of Pittsburgh
, by Michael Chabon - an engaging coming-of-age novel about a young man who has just finished college and is hanging out in Pittsburgh. The novel has vivid and accurate descriptions of what it is like to be young, in love, and in Pittsburgh. The movie is coming out this month; I will definitely go see it.

I am currently reading Lorrie Moore's Birds of America, a collection of short stories; I really like it so far.

* Zelda was diagnosed with schizophrenia and spent decades of her life in and out of mental institutions. It seems, however, that this was early 20th century schizophrenia: she had periods of being better and period of being worse, so it is more likely that she was manic depressive. Scott's Tender is the Night is based heavily on his experiences with Zelda's illness.

Pride and Prejudice and Zombies, by Jane Austen and Seth Grahame-Smith



I discovered this book while checking out at the bookstore yesterday. While I've only read the first page, I recommend that you check it out. In this funny "novel" published by Quirk books, Grahame-Smith has taken Austen's classic novel and changed it to accommodate some zombie parts. A blurb:

...As our story opens, a mysterious plague has fallen upon the quiet English village of Meryton—and the dead are returning to life! Feisty heroine Elizabeth Bennet is determined to wipe out the zombie menace, but she's soon distracted by the arrival of the haughty and arrogant Mr. Darcy... Complete with romance, heartbreak, swordfights, cannibalism, and thousands of rotting corpses, Pride and Prejudice and Zombies transforms a masterpiece of world literature into something you'd actually want to read.

Below is the opening of the book:

It is a truth universally acknowledged that a zombie on possession of brains must be in want of more brains. Never was the truth more plain than during the recent attacks at Netherfield Park, in which a household of eighteen was slaughtered and consumed by a horde of the living dead.

"My dear Mr. Bennet," said his lady to him one day, "have you heard that Netherfield Park is occupied again?"

Mr. Bennet replied that he had not and went about his morning business of dagger sharpening and musket polishing--for attacks by the unmentionables had grown alarmingly frequent in recent weeks.

The book also includes fun illustrations of the battles involving zombies. I did not buy this book because I was skeptical of its ability to capture my interest throughout the whole thing, but let me know if you find it a good read.