Learn Haskell in a Day

I was intrigued by Raditha‘s posts on learning Ruby and Python in a day (though they were dragged to 48 hours). Now I’m going to make that inspiration into action by trying to learn Haskell in a day.

Why Haskell?
I’ve always wanted to learn a functional programming language. Have never even written a Hello World with one. Heck, I even don’t know what functional programming is. My first choice was Clojure, but then, after spending some time on the web, decided it would be Haskell. So the main reasons were:
1. Haskell is purely functional
2. There’s a strong, near-fanatical community. Smaller ones are frustrating to work with (that’s what she said).
3. I had heard of ppl solving problems with Haskell in numerous forums
4. When asked what languages I’m proficient in, it’s always nice to add “and, of course, Haskell” at the end.

As the tutorial, I chose LYAH (Learn You A Haskell), which is the ‘funkiest way to learn Haskell’. It’s aimed at those who already know how to programme, so, yeah.

And this will be just a crash course. I very well know you can’t become a master in a language within 24 hours. What I’m trying to achieve is being able to write code to solve basic problems and being able to read Haskell code when I see some.

And here we go:
Language: Haskell
Compiler: GHC (This gets installed when you install the haskell-platform)
Editor: Vim
Tutorial: LearnYouAHaskell
Motivation level: High

Was going to start in the morning, but started just an hour ago coz of the darn slow connection which is a luxury in this wilderness. It took more than half-an-hour to download the 70MB of packages for haskell-platform, just imagine. Hoping to finish by this time tomorrow if the connection keeps up till then.

As of this writing, I’m in the section “I’m a list comprehension”. Here are a few interesting stuff I came across so far:

Functions
As you may have guessed, functional programming languages are all about, well, functions. So is Haskell. Declaring a function is as easy as declaring a variable.

squareMe x = x * x

Functions and parameters are separated by spaces and not parentheses, just like in Bash. Also, if the function takes exactly two parameters, you can call it as if it were an infix function. For example, the ‘elem’ function takes two parameters. If we wanted to pass 2 and someVar to it, both of the following will work:

elem 2 someVar
2 `elem` someVar

Using infix functions can be less confusing in many circumstances.

Error messages
Ugh. The error messages Haskell gives are almost incomprehensible. If you tried to add a string to an integer it would be,

<interactive>:39:3:
No instance for (Num Char)
arising from a use of `+’
Possible fix: add an instance declaration for (Num Char)
In the expression: 2 + ‘c’
In an equation for `it’: it = 2 + ‘c’

An if statement is an expression
You can do cool stuff like this:

coolFunc x = (if x > 10 then x else x*2) + 1

So if we passed 4 to coolFunc it would return 9 (= 4*2 + 1) and if the argument happened to be 15 it would return 16 (= 15 + 1).

Haskell is lazy
Haskell is a ‘lazy‘ programming language. By lazy, it means that it won’t compute anything until its result is specifically asked for. For example, we can use the following to obtain the first 20 multiples of 7:

take 20 [7,14..]

[7,14..] denotes the infinite array 7,14,21,28 and so on. The above statement asks for the first 20 elements of this infinite array. In another language, the interpreter would try to calculate the infinite array first before taking the first 20. But since Haskell’s lazy, it doesn’t do anything until the function ‘take‘ asks for the first 20 elements. It will only calculate the first 20 elements.

Quantum particles are like boos

If there’s one single subreddit that’s worth subscribing to, it’s /r/explainlikeimfive. The subreddit aims at answering to questions like you’re explaining to a 5 year old, i.e. in a language that everyone can understand.

When I come across a good explanation I clip them to my evernote. I was going through some notes today and came across this clip from a post that dated about two months back. The post explains the work of 2012 Nobel prize winners. There is an explanation that says quantum particles behave differently when we observe them. Someone raises the reasonable question “How do they know they are doing something different when we don’t observe them if we can’t observe them without affecting them previously?” Look at the explanation it got (permalink):

super mario boos

It’s like the boos in Mario. Whenever you look at (measure) them, they stop moving (act like particles). When you look away, they chase you (act like waves). When you look at them again, they’re somewhere totally different.

And just like boos, sometimes they go through walls. But only when you’re not looking.

Exactly what a 5-year would need to understand what’s going on. What’s more, it explains a scientific principle so brilliantly that any of us can understand (albeit it may not be 100% technically correct).

I highly recommend reading the whole thread.

Few hours with App.net

So I joined app.net today. An year’s subscription costs $36 and there’s a monthly option for $5. I chose the latter for a start.

The global feed, similar to Twitter’s public timeline

It’s pretty much a Twitter-like service with a slightly different vocabulary. You create posts with a maximum length of 256 characters, as opposed to Twitter’s 140 limit on tweets. You can @ reply to other people’s posts and repost the good ones (just like retweeting). Or quote them (old-school retweet) and star them (favorite). There’s no counterpart to Twitter’s DMs as yet, but it’s coming soon. You can follow and unfollow other users.

How does it differ from Twitter?
For one thing, app.net will never advertise or sell their users’ data, as promised by the developers. It will be funded by the subscription fees. This also means only the people who are really interested will join app.net.

Secondly, app.net _is_ an open-source API. It focuses on users and third-party developers. Compare this with Twitter which now shuns third-party apps. Everyone had big hopes on Twitter a few years back, but not anymore. I tweeted a good post on this by Terence Eden some time back. Everyone should read that.

App.net may still be in its early stages, but developers have gathered around the platform and are building apps actively. There are quite a few apps already in the app.net directory. Other than the Alpha webapp by app.net itself, I tried out Dash for Android, NoodleApp for the web, and Texapp, a text-based client written in Perl just like Ttytter by the same developer. Best of all, you can use app.net with IFTTT as well.

appnetstats gives a realtime overview of the current app.net stats. Currently, majority of the users are developers and geeks, which is perhaps a good thing. Lots of constructive conversations going on.

Is app.net going to kill Twitter?
I don’t think so. Not being free will make most users stay out of it for the foreseeable future and stay with Twitter. But app.net will grow into a good community without any of Twitter’s stinking aspects. I really hope this will be the case. It’s been just a few hours, and if the going gets good I may subscribe for a full year. One may argue that no one should pay for a service that you can get for free, but in reality you cannot get what app.net offers from Twitter. You just can’t. They have explicitly defined their core values in their home page and Terms of Service in github.

Follow me on app.net if you’re there; I go by @thameera.

Quantal Quetzal – the all new Ubuntu 12.10

It’s been 5 days since Ubuntu 12.10 (aka Quental Quetzal) was released and I downloaded the ISO on 19th, but got the time to install only today. Finished the install just 30 minutes back from the time I started writing this. By the way, the following ain’t gonna be a review, just some stuff I did after installing and the problems I had. If you want a review let me google that for you.

Ubuntu no longer fits in a CD. It’s got bigger (that’s what she said). The ISO is 800 MB now, so if you’re not installing online, you need to create a DVD or a USB.

I had previously fucked up the whole 12.04 install by messing up with xorg.conf, compiz and even wine, so formatted /home as well. A fresh install, literally. It went without a hitch.

Was expecting everything to work smoothly after the install, but some did not. Nvidia drivers do not come by default (which is normal) but they did not appear under Additional Drivers as well. I tried sudo apt-get install nvidia-current and restarted, but the screens were messed up. Unity launcher was hidden and the screen resolution was fixed. A bit of googling showed that this was a known bug in the kernel. The following workaround solved the problem:

sudo apt-get install linux-headers-3.5.0-17-generic
sudo apt-get remove nvidia*
sudo apt-get install nvidia-current

The dual monitor setup got detected and the display was set to TwinView automatically, so had no need to do them manually as I’ve mentioned previously in the other blog. Anyway when you move the mouse from one monitor to another, there’s this deceleration which is a headache. This could be disabled by going to Displays and turning off Sticky Edges.

I keep the Unity launcher on both desktops coz it’s more convenient that way

Installed ubuntu-restricted-extras next. Nothing special there.

Then I downloaded the Google Chrome deb and tried to install, but this gave ‘The package is of bad quality’ error. As it turns out, this is also a known bug and continuing with ‘Ignore and install’ is the way to go.

The next step was to completely remove Ubuntu One. Coz that’s how we roll. The command is:

sudo apt-get purge ubuntuone*

In Quental, there’s this new Online Accounts section, in which you can log into most services like Twitter, Google and Facebook. After logging in I noticed that the Messaging icon was missing from the top panel. This could be turned on by going to Broadcast Preferences and checking Start service at login.

Some of the things I’m gonna do next are installing the blinking messaging menu icon and installing some cool stuff like Everpad, fogger, pinta, clementine, rubygems, ttytter and apvlv. And ccsm of course (just noticed it’s missing). Then enable wobbly windows. And then edit /etc/fstab to my liking perhaps. I may post some tips on new features, workarounds, etc in Accidents Happen.

Since it’s been less than hour, it’s too soon to tell how good Quental is compared with Precise (12.04). Anyway I’m disappointed by the nvidia issue. Fuck you nvidia!

On Galaxy Note II

The Note started as a controversy, but in the end, it was a resounding success. Contrary to many initial reactions, people actually liked the big screen. More than 10 million were sold. I’ve been using the Note for over 8 months and was constantly asking myself, is it even possible to come up with a better phone? Turns out, it is. Welcome the Samsung Galaxy Note II.

Yes, it is!

Thanks to It’s About Gadgets by Etisalat, I got the chance to use the new monster for a week. And, ugh, I forgot to take any photos or screenshots, so all the photos in the posts will be stolen ones from the interwebs.

The initial reaction when I got the Note 2? This guy is fast! Of course, it goes without saying that Note 2 is one of the fastest phones currently on the market (specs here, comparison with Note here). With a quad-core 1.6GHz Exynos processor and 2GB RAM, it’s got more power than my previous laptop. The transitions are pretty slick. Could play Max Payne without any lag whatsoever. Note that (no pun intended) I tried everything in the stock TouchWiz launcher and without many third-party apps running in the background, so yeah, you get my point.

Samsung Galaxy Note II

Jelly Bean comes pre-installed in Note 2 with better camera, actionable notifications and all. (Even though the Note comes with Gingerbread, it’s upgradeable to Jelly Bean.) There’s this pop-up video player thingy and other fancy apps.

All the nonsense aside, let’s talk about the size. The Note’s screen was 5.3″, whereas it’s 5.5″ in Note 2. However, it’s less wide than the Note. Which means it feels better in the hand. Several of my friends who hated the original Note’s dimensions said they like the new design. Then how come the bigger screen? Yes, Note 2 is longer than the Note. It’s like some idiot took the Note and pulled it from either side. This has made the resolution to go down to 720×1280 (as opposed to 800×1280 in the Note). And less pixel density. I personally prefer what it was like in the original Note.

Note 2 (on the left) vs the Note

S-Pen functionality is much better with the Note 2. There’s some kind of sensor in the S-Pen slot, so when you take it out or put it back in, the phone knows. Taking the stylus out automatically takes you to a screen with many S-Pen-capable apps. Also a notification icon appears in the top bar saying that the pen is not on the slot, reducing the chances of losing it (as happened with my Note. Had to buy a replacement and it wasn’t cheap). It detects when you hover the pen above the screen as well. For example, if you hover the pen over the pictures in the Gallery (or events in the calendar), they will quickly zoom in and zoom out once you move the pen away. And stuff.

Hovering the pen over Video Player’s progress bar

Regardless of how much I hate the new screen and the dimensions, I prefer the Note 2 to Note. I would buy if I could. Apparently you’d be able to grab one from Etisalat itself in a few days. And there’s this small video interview I had with them about Note 2 which will be available in their Youtube channel in a few days.

UPDATE: Here’s my interview with Amitha on the Note II.

How I wish we didn’t have to wish

Don’t you just hate wishing people on their birthdays? Especially when it’s not in real life? In real life, you can just ‘adoh happy birthday mchan, when’s the party?‘ and all. It’s simpler in Facebook: just a ‘happy birthday mchan!‘. But not so on Twitter.

I try to ignore birthdays as much as I can. Nobody will tell you it’s his birthday, so, you see, he doesn’t really know if I know if it’s his birthday, even though I know it’s his birthday and I know that he knows that there’s a good chance I’ve heard of his birthday but he really can’t prove it, so it’s just a matter of simple logic.

I wish this was always the case, but then, sometimes you really have to wish (pun intended). Like today, when I go to twitter everybody’s wishing MoAwesomeSauce for his birthday and you go to facebook and you see photos of his office treat or whatever, and when you go to twitter again you find him thanking for all the wishes he got, and then when you think it’s all over here come more ppl wishing him and then again more thanks follow.

*#?$. This is the point when you say ‘oh what the hell’ and try to compose a happy birthday message. What do you say? Happy birthday mchan? After you look at all the wishes he’s getting, such a simple one would make him think I’m like wishing for the sake of wishing, so no. Many happy returns of the day? Same story. And too common. Happy birthday mchan, when’s the party? I look at the wishes he’s got and none of them mentions about a treat so perhaps he’s the kind of guy who doesn’t give out treats? So… no.

His name is MoAwesomeSauce, so I could add some ‘awesome’ into the wish and make him feel good? So I write this and press Enter:

[tweet https://twitter.com/thameera/status/254463321007341568]

WTF! Isn’t that the lamest birthday wish ever? ‘Awesome’ is mentioned twice and there’s a smiley at the end! And the second sentence doesn’t even make any sense! Awkward at its best. And the worst part of it all? He thanks me with just a ‘thanks mate’! All the hardwork to that wish-with-two-awesomes-in-it dismissed with a simple ‘thanks mate’?

Has the world always been this way? Just three months to the apocalypse and we’re still sharing lame awkward birthday wishes? Will everything be alright after Sarath Fonseka forms his new party? Will Sarath Fonseka ever form a new party? Is he even out of prison yet?

So many questions. There’s nothing one can do but simply wish MoAwesomeSauce a very happy birthday and not think about it anymore.

Be lazy, be awesome

Learned that awesome people are generally lazy. Not quite sure where I got that from, but thought of giving it a try. It won’t hurt to try something like that, right?

no no no

Being lazy has its share of problems though. You can’t regularly update the blog if you’re lazy. I would open up wordpress.com every once in a while and start typing in a new post, only to remember that if I do that, the whole point of being lazy is lost. Damn.

Anyway I started this new blog kinda thing called Accidents Happen (don’t ask). Do subscribe to its feed. I’m hoping to choose two lucky subscribers randomly and give them Rs 500 gift vouchers from Vijitha Yapa Bookshop. Well, not really, but you should really subscribe just in case I did. The goal is to publish at least one small post a day there, but then again, being lazy won’t let you do that. Fuck.

During the few days I’ve been trying to act lazy, it dawned upon me that laziness is a productivity killer. But if that’s the price you have to pay for being awesome, you can’t complain, can you?

In other news, I gave up the idea of buying a rubber duck, coz my Ravage transformer seems be able to serve the purpose just fine.

Transformer USB pen

Getting ready for some hardcore debugging

PayPal for Sri Lanka

PayPal doesn’t fully support transactions for Sri Lankans. Yes, we can pay for stuff with Paypal, but we can’t receive money from others. This has always been a major problem for the country’s freelancers. Most clients prefer making payments via Paypal. There are several other options like Moneybookers, but none of them are as popular as Paypal nor are supported by most sites.

Indi wrote about this some time back. According to his post, the culprit is the Central Bank of Sri Lanka. You can send out as much as money you want but you can’t receive any. No inflows; only outflows. This is ridiculous.

Now there is an online petition in change.org demanding the restrictions for receiving money through Paypal be lifted. Initiated by Budhajeewa, the petition has received over 950 signatures as of this writing. The target is 1000, and will be increased most probably once this target is met. There is a Facebook group and a small site as well.

Please do sign the petition if you haven’t already and share the link with friends.

n7player is on sale!

The home screen

Zoom with multi-touch to view albums

n7player is perhaps the most visually appealing music player for android. I’ve been using it since it was in the beta stages and have never looked back. Of course, I’ve used doubleTwist Player (which I still use as a backup), PowerAmp and Mixzing; but none could compete with the beauty of n7player.

Another feature I love about n7player is that it lets you choose what your music directories are. Most other players get crowded with mp3 files that are not in your music collection. Besides this and the stunning appearance, it’s got a graphic equalizer, bass boost, an album art downloader, sleep timer and several other features.

Recently added landscape view

Not that it’s perfect in every aspect. The lack of control the user has over the playlist will get apparent if you use it regularly. This is the biggest grievance you’d hear from a n7player user. Hope the devs would add better playlist management features soon and, mind you, this has never been a reason to ditch the player over others.

The free version of the app is only a 14 day trial. The full version unlocker usually costs $2.89, but it’s on a sale for $0.99 for a limited time. Believe me, you won’t repent even if you bought it for the full price.

LXDE on Ubuntu

The laptop won’t let me dual boot. That’s coz the lappy isn’t actually mine, it’s the office laptop. So I was running Ubuntu in Virtualbox all this time. Ubuntu 9.10  (I know!). But then I switched to 12.04 – Precise Pangolin. Unity is pretty cool now compared to what it was back then in 11.04. However it’s a no-no for running in a VBox. Switched to gnome classic sans effects which improved the performance drastically.

I had used LXDE for a few months about an year back in my netbook. So I thought, why not give it a go again? Without removing the existing gnome packages, I typed,

sudo apt-get install lxde-core

into the terminal. It gave me the LXDE desktop, but that’s as far as it went. Just the desktop. No Leafpad, no PCMan, no LXTerminal, nothing. Hey, that isn’t LXDE! What’s LXDE without Leafpad or PCMan? So I went ahead and typed,

sudo apt-get install lxde

and, voila, here I have what I wanted. (Lesson: don’t install lxde-core, just use lxde and it gives you everything)

LXDE desktop on Ubuntu

From left to right, Leafpad, PCMan file browser and LXTerminal (click to enlarge)

Okay, the interface isn’t as polished as that of gnome, that’s a given. It’s only supposed to be lighter and faster. But unfortunately it felt like the system isn’t much comfortable having LXDE around. It felt like the kernel’s carrying a bulk. Not as smooth as the classic gnome experience. I know this isn’t the way it’s supposed to happen, so I’d try this for two or three days and switch back to gnome. Good thing I didn’t remove the gnome packages before installing.

Oh wait, perhaps it’s a good time to try out XFCE!