Tuesday, May 21, 2013

How to Learn Haskell

For whatever reason, Haskell's curve of interest has been going up again. Haskell is a philosophy as much as a language, and a controversial one at that. Haskell is lazy and purely functional language. I will explain what each of those are at the bottom of this article. This is more specifically about how to set up a good Haskell learning environment.

Learning Material
For learning Haskell, look no further than http://learnyouahaskell.com/. Learn You a Haskell is written in a similar manor to Land of Lisp with its quirky prose and downright hilarious examples. Due to Haskell's lack of wide use, this book has a near monopoly on the task of learning Haskell; which is fine. The book covers everything very in-depth. If there is something in here, you will need it to use Haskell effectively, so do not skip around, especially when the problems gets harder (like the RPN calculator). Extra learning material and support can be found in the sidebar of http://www.reddit.com/r/haskell/






Development Tools
Haskell is nothing without a good text editor. There are some relatively advanced formatting standards within Haskell (especially with guards: see below). The best editor for Haskell is subjective, but I will cover the tools that I have used for Haskell development and try to take an unbiased look at each one. Before reading the recommendations I have to come clean; I use Emacs, so I may lean towards it a little bit and compare a lot of the tools to Emacs.

     Eclipse FP
Eclipse FP is a plugin for the Eclipse framework that provides Haskell project support. Extra goodies can be installed via cabal (the haskell "package manager"). If you can get it working on your system with all of the recommended goodies (scion for syntax highlighting, ghc-mod for ghci integration, etc) then this could be a very easy and welcoming development tool. Drawbacks are the chance that it will NOT work (it didn't for me, but this was the first tool I tried to use. It's probably very good) and having to install Java as well as Haskell (~128 MiB in total).

   Leksah
Leksah ("Leck - Sah", Haskell backwards) is  full-blown Haskell IDE written in yours truly (Haskell). It has some interesting features, like listing the type signature of a function when you type it (think: Javadoc lookup in other IDE's) and trying to compile the file on every keystroke, showing you (and underlining) when you make a mistake. It supports editing of Cabal files, project browsing, and graphical integration with the Haskell debugging tools. For serious Haskell users, consider Leksah. I found that it is too early in its development to be useful to me (I experienced several crashes without file saves, but this may not happen to you), but the amount of tools this brings into one project makes it enticing if you really want to get your hands wet with Haskell. Since this is a post about learning material, I don't think that this would be appealing. 

   Emacs
One many in my IRC channel said that Emacs is "Not an editor, but an operating system with a [censored] good editor". Emacs has been around for a long time and is very extensible, which means it has a lot of tools written for it. This is perfect, because Haskell matches this description very well. To make Emacs useful with Haskell, one first must install el-get  and then use el-get to install haskell-mode, ghc-mod, and scion. Be sure to add the appropriate code into your .emacs file. 

The benefits to using this is that C-c C-l will load a file into a ghci minibuffer, which is great for testing out programs on the fly as well as saving them for compilation later. Yes, Eclipse has features like this, and so does vim with the right plugins, but Emacs and these extensions happened to hit my sweet spot. Look around and see what is right for you. in this department. Emacs can also extend into an IRC client, so asking for help on #haskell on Freenode is very simple.

Learning Strategy
Haskell is overwhelming to many. If you do not know a functional language already, it may even be wise to learn a bit of Common Lisp before using Haskell. Haskell is purely functional. There are no loops or IO outside of the IO Monad, so it is a major forced paradigm shift. I would learn enough Haskell from "Learn You A Haskell" to be able to work on projects (pattern matching, functors, etc), work on some, and go back to where you left off to finish up your learning. Learn You A Haskell is a very in-depth book and without the context of some projects it will all get jumbled.

Wednesday, May 8, 2013

5 Great Linux command line Programs

Linux has withstood the test of time and gathered an interesting repertoire of software over the years. This is a list that moves from my most used to my least used software on my system. Some of the tools here are widely used and advanced, but if you aren't already using them they're worth a gander.

1. tmux
Ah, where would any of the experienced linux users be without tmux or GNU/Screen? Tmux is a terminal multiplexer, meaning that it can split a terminal session into multiple panes that can be navigated with the keyboard.  The panes can be resized and sent to windows (like graphical workspaces). The best feature is that this is client-server software, and if you close the window where you are running tmux it still won't die. For persistent ssh connections or IRC chats, tmux is king in the command line.

2. ssh
ssh is the secure version of telnet. It allows a user that is using openssh-server on their host machine to connect remotely from the command line to perform tasks on the host machine. If you are using X as your display server, you can even forward graphical applications over ssh or access the filesystem with sshfs.

3. git
Git is the version control programmed by Linus Torvalds, the same guy that wrote the Linux kernel. Git allows a user to keep snapshots of changes of a project on their computer. git is SCM and not very useful for binary data, but it works wonders for projects that need collaboration or just a very secure way to roll back changes. Git will use all available cores for compression, making it the fastest SCM in existence. Git is supported by websites like Google Code and Github.


4. vim
Vim is Vi-Imporoved. For readers who are unaware, vi is the standard Unix editor. If you have a Linux system, you have vi (this is even true for Android). Vim improves on vi extensively, adding syntax highlighting, improved navigation, and extensive plugin support. Even though graphically I prefer emacs, for remote sessions or quick edits nothing beats Vim. What sets vim apart from Emacs is modal editing, where the user has two modes to edit the file in.

5. mplayer
Last but not least we have mplayer. mplayer (and mplayer2) are tools for the command line that can play video and music of an incredible amount of formats. mplayer will use X to draw a window for a video, but it can play video in text completely with ASCII animations.






Using Maybe in Haskell

Haskell is a quirky language to say the least. I've been playing around with it for about a month now. Today somebody pointed out that I was "doing it wrong" with one of my functions. I had it defined as (roughly)

pos :: (Eq a) => [a] -> a -> Int
pos [] _ = 0
pos a@(x:xs) y
  | (y `notElem` a) = -1
  | x == y = 0
  | otherwise = 1 + (pos xs y)

The obvious problem with this is that if y is not a part of the list (and yeah, it will check every time, also bad) it returns -1. -1 is a hack in a lot of procedural languages that means "Woah there nelly, something went wrong". In Haskell it doesn't have to be this way.

What Maybe is
Maybe is a type with two type constructors (Just and Nothing). Just uses a type variable whereas nothing has no parameters. Either the thing is returned or it is not, end of story.

Here is a function that returns an int if the number parameter is less than 10, nothing otherwise.
test :: Int -> Maybe Int
test x
  | x < 10 = Just x
  | otherwise = Nothing

Remember that Just and Nothing are not types, but rather they are type constructors, which is why we can put them in the type signature under "Maybe".

How to use Maybe values
To "extract" a maybe value, you either have to make the function accept a maybe or extract the value beforehand.

Extracting the Maybe Value
Here is an extracting function that if it is a Maybe of a it will return the a, but otherwise unit (Won't actually work; just case in point)

extract :: Maybe a -> a
extract (Maybe a) = a
extact (Nothing) = ()

Make one of these extracting functions for whatever type you think you will be using.

To destructure a maybe within the function, just include the type constructor like was done in extract. This is what pattern matching was made for.


Monday, May 6, 2013

All about i3 - A tiling window manager review

i3 demo:


I have long been a user of tiling window managers. They provide a distractions-free environment, and as my work-load has been increasing, so has the number of distractions that the Linux desktop can throw at me. Sometimes it's a good thing to shut everything out and get to computing.

The number of frills that i3 comes with is SO low in fact, that it doesn't even offer a clock! When you log in you will see a minimalist interface kind of like this (minus the bar at the very bottom, that was my idea and I will cover that later)
I didn't know where to start. I couldn't do anything, and it is all my fault. I hadn't researched i3 at all. I hadn't the slightest clue how to open a terminal to "man i3" or use "google-chrome". Worse yet, I didn't even know how to exit the session, so I had to escape to a tty and pkill gdm. I was not liking i3.


It is very important to realize that i3 has a VERY steep learning curve that will gobble you up if you don't put in some effort. The end-all-be-all guide to i3 is http://i3wm.org/docs/userguide.html, the i3 user guide. It will instruct you on everything you could possibly want to do with i3. It explains the philosophy behind the window manager as well as how to use it, so poke in and read around even if you aren't an i3 user (yet).

The advantages of i3
i3 is peculiar. When you first start opening windows, you will notice that it doesn't do what you would expect from Awesome or dwm. It actually uses all of the screen evenly.
The user can resize windows with their mouse or with the keyboard. They can move windows and change the layout of the workspace. The layouts change the way the windows are presented. There are two ways to use all of the screen real-estate, and two ways to magnify only one window at a time. The ability to have one window open at a time and tab through the rest is surprisingly handy, or at least I thought it was a nice escape from the mess of windows I was making on my desktop.

This provides unparalleled customizability concerning the way that you, the user, arranges the windows. Think of i3 like you would think of GNU screen or tmux, just for X clients. The reason is that each of these "containers" can be further split and assigned splitting rules, so that a user can emulate the one-big-many-smaller paradigm from awesome or dwm.

A mess I made playing with i3

The disadvantages of i3
Disadvantages in i3 are PEBCAK. Everything can be solved in i3 with the well documented protocols and extensive configuration file. However, there are some really hard problems to solve that are not there out of the box. For instance, i3 does not come with a clock (although it does come with a system tray, thankfully!). To combat this I wrote a program that can be evoked that reads the time off (espeak piped into a C++ program using strftime) and put tint2 on an infinite loop (i3 will kill tint2). Are these solutions? No. There should be a textclock widget like in Awesome. But this, like the rest of i3's problems, can be solved with a bit of ingenuity and elbow-grease.

My opinion
As a control-freak, i3 is seemingly a nice tool to take full control of your window manager. There aren't any distractions, the key bindings are sane, the RAM usage is super low (< 5 MiB), and it is oh-so-configurable. It is a lot of effort, but if you are fed up with the glitz and glamour of the mainstream desktop environmnets, come and play on i3's jungle gym.

Saturday, April 27, 2013

How to install Google Chrome in Ubuntu (13.04)

There is a problem with Ubuntu 13.04 that disallows Google's Chrome web browser from being installed without making a fuss. In short, the problem is that google needs libudev0 (>= version 147), but that package is not available in the repositories.

The Solution
libudev0 may not be in the Ubuntu repositories, but it IS in the parent-distribution (Debian)'s repositories. We can go there and download libudev0, and then install the program.

1) Go to http://ftp.us.debian.org/debian/pool/main/u/udev/libudev0_175-7.1_amd64.deb and download the .deb

2) Install the file like you normally would (double click it in Files or use dpkg -i).

3) Download the Google Chrome package from https://www.google.com/intl/en/chrome/browser/thankyou.html?brand=CHMB

4) Install the Chrome .deb file however you comfortably do so.

Extra
If you messed up beforehand, you will want to run "sudo apt-get install -f" from the Terminal to clean any broken packages that apt tried to get.

Friday, April 12, 2013

Ubuntu 13.04 Beta Review ** April 12th, 2012

I am the average Joe Linux user. Ubuntu helped to ease me into the world of Linux gently before plunging into the world of commands and ttys. I have this nostalgic love for Ubuntu, and even if I don't agree with some of their latest goals (let me go on record by saying I do like their direction of mobile) I have always considered it a very friendly distribution. This was before I used 13.04 beta.
What's the ruckus?
Well, Ubuntu is that gateway Linux distribution that the newcomers will use to make the transition easy, right? Well, the latest Ubuntu is going to give them the idea that Linux is inheritly buggy, slow, and crash-prone which is not the case at all. Canonical has been working so hard on its mobile operating system, display server, startup manager, and all of its other pet projects that they forgot to make a good distribution. Whoops!

What is even worse is that this is a long term release. We will be stuck like this for a long time. Imagine if Windows Vista had become the de facto Windows computing environment  of the world. We'd all be on Linux if that were the case, and 13.04 makes me want to move to Windows.

The Problems
One of my biggest problems was the lack of improvement over 12.10, and even 12.04. 12.10 was a copy+paste of 12.04 with some features like shopping and web lenses with previews (which are very helpful, in my opinion) and some optimizations of both user experience and resource consumption. 13.04 is exactly that distribution with one or two minor features and some new icons. There was going to be a VERY desirable feature for lenses included, but they were dropped at the last minute like Wubi.

At one point I had the gnome-settings-manager crash, which also brought down compiz and gtk-window-decorator. This left my desktop in an unusable state where windows did not even reply to keyboard commands. I had to switch to a TTY and pkill lightdm to solve the trouble.

I have also had countless popups telling me there are "problems with the system", and a few of those notifications crash themselves and become unclosable, even after a pkill. I call them the kamikaze windows.

Another big problem is the lack of workspaces. Yes, they aren't included at all by default, folks. They can be enabled through compiz, but that's an unneccessary step, especially considering the option for workspace keyboard combinations are included in the settings manager. While we're talking about the settings manager, let me just warn you that every now and then keyboard shortcuts will decide not to work, so be ready for that.


The Verdict
Now that the venting is over, it is fair to say that this IS A BETA. It most certainly will get better with the final release, but for now it is in an almost unusable state. "Do not use on production machines" is a warning that Canonical gives that I would actually advise following.

Saturday, March 23, 2013

Opensuse 12.3 Review

Opensuse has recently released its newest version in its line of Linux operating systems. I have had a few run-ins with Suse in the past at much earlier release dates. 12.3 has gotten a lot of publicity for how well put together it is, which is one reason I was left so gravely disappointed after using it. In this review I am going to try to look at the good of Opensuse, since some of the problems I experienced only apply to those with certain hardware conditions, but there is also some bad to sift through.

The Desktop
One nice thing about OpenSuse is the KDE setup it comes with by default. They've put a lot of effort into making both the animations that are enabled and the themes that are applied visually pleasing (if you happen to like green). Although it is good looking, it is not as functional as you may want it to be. It ships with KDE 4.9, but that can be updated immediately by switching to Tumbleweed (the rolling release system for Opensuse). Similar effort is applied to the Gnome Opensuse flavor, but not to the XFCE, which was disappointing. Their XFCE .iso comes with some bland defaults with light branding. It's really nothing to right home about.

The Applications
The default applications are more-or-less standard. Libreoffice, your DE tools, Firefox, Vim (I was happy to see that) etc. Gimp is not included. One application that always gets coverage in Opensuse reviews is YaST (Yet Another System Tool). It truly is an amazing utility, with which you can graphically perform tasks that on any other distribution you would be doing by hand. Graphically changing hostnames, installing packages, changing kernel parameters, changing GRUB around, setting up a LDAP / Mail server, etc. It can all be done through YaST.

The Not-so-good
So far it is sounding like a very good distro, no? Well, there is one minor issue that you will run into. To enable networking, you have to select a check mark in the NetworkManager applet for whatever DE you're using. After it's selected you must reboot to start using networking. It's a minor annoyance for some, but it grows into bigger problems for others.

I have a hardware condition that disallows proper shutdown. Thanks to this networking problem I have absolutely no internet access whatsoever. This is an incredibly rare case, but it's bound to effect others out there. And even if it never effects your computer to this extent, it WILL happen to you.

On first run, packagekit will persistently run, causing you to either have to kill it or reboot. This has something to do with it checking for updates and crashing.

Would I use this distribution?
I really wanted to. I downloaded the .iso to move from Sabayon 11 to something a bit more Enterprise, but ran into some bugs that stopped me in my tracks. It is destined to become Ubuntu fodder.

Who would use this distribution?
Don't get this review wrong. Opensuse is one of the best Operating Systems for enterprise workstations and home desktops. It is an Operating System crafted specifically for desktop and laptop use, none of this touch-friendly nonsense that some companies have started introducing. If you are fine with some rough corners, use it. It is the best default KDE experience I have ever seen, even if it is an earlier version. I just think that they should have polished the distribution a tad bit more before releasing it.