Nick Mudge Ignition Software Consulting & Development

I'm continually amazed by Javascript. It is such a secretly amazing language. Look at this Javascript array:

listfun = [["My RSS image", "http://nickmudge.info/valid-rss.png"],
           ["Google Birthday image", "http://www.google.com/logos/9th_birthday.gif"],
           ["Blogger image", "http://www.blogger.com/img/logo100.gif"]]

Beautiful, but it doesn't look like an array, it looks like a list! A list of lists. So is it an array or a list?

What does a list definition look like in Haskell? It looks the same! This code compiles as Haskell and interprets as Javascript. So is it Haskell or Javascript?

I started writing lists, I mean arrays, like this in my Javascript code recently. It's a bit of concrete evidence for me that Haskell/functional programming is sneaking into my programming in other languages. I didn't realize that this Javascript is Haskell until tonight.

On another note: Check out this 3D animated graphics written in pure Javascript/css/html, no images, no flash, nothing else. Got to love borders and triangles.

stesch from programming.reddit.com: "JavaScript is a magic thing. Everybody sees something from his favorite language in it."

Comments

chessguy
27 September 2007

An interesting point. I write server-side javascript for a living, and have really been enjoying it. I do have to keep catching myself though, referring to JS arrays as lists, when people who don't know haskell wouldn't necessarily call them that. Two additional things are worth pointing out:

1.) While the syntax is the same, the one nice thing about JS is that (as far as I know), arrays are O(1) access. So while a haskell programmer shudders every time he sees list !! 3, it's perfectly natural to do list[3] in JS.

2.) Arrays actually have some nice functional methods that will be familiar to haskell programmers. For example:
array.map(f) === map f array
array.every(p) === all p array
array.filter(p) === filter p array
array.reverse() === reverse array
array.some(p) === any p array
Nick Mudge
nickmudge.info
28 September 2007

That's awesome. Thanks.
Name: (required)
Email: (required)
Website:
What has four legs, rhymes with bat and says, "Meow?" (One word answer.)
Spam Filter: