Hari's Corner

Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and then

So on to learning Haskell

Filed under: Bits and Bytes by Hari
Posted on Wed, Oct 26, 2011 at 10:58 IST (last updated: Thu, Nov 3, 2011 @ 14:57 IST)

In this series Next >
Haskell is quite an interesting and absorbing programming language. For those coming from an "imperative" programming background (mainly languages like C, C++, Java, Python etc.) Haskell can be quite a shock in the system.

However, learning the functional paradigm has always been on my wishlist for a long time and I eventually took the dive.

Here's a simple Haskell program I managed to write on my own after a few hours of reading tutorials and understanding concepts. This is a Caesar cipher program which accepts a string as input from the user and shifts each character by one in the alphabet. (that is 'a' is replaced by 'b', 'b' by 'c' and so on. 'z' becomes 'a').

import Data.Char
caesarenc :: Char -> Char
caesarenc 'z' = 'a' caesarenc 'Z' = 'A' caesarenc ch = if isAlpha ch then succ ch else ch
main :: IO ()
main = do putStrLn "Enter a string to encrypt (return to quit): " st <- getLine if st /= [] then do putStrLn $ "The encrypted string is: " ++ map caesarenc st main else return ()

I highly recommend this tutorial. It's very readable and understandable for those from coming a procedural/OOP programming background.

And yes, the #haskell freenode IRC channel is also populated by kind folk who make you feel comfortable even if you are an absolute beginner.

In this series

No comments yet

There are no comments for this article yet.

Comments closed

The blog owner has closed further commenting on this entry.