So on to learning Haskell

Filed under: Bits and Bytes by Hari
Posted at 10:58 IST (last updated: Thu, 3 Nov 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.

No comments yet

Leave a comment »

There are no comments for this article yet.

Leave a comment

First-time comments on this blog are moderated.
Your name*
Email ID*
(wont' be published)
Website
Your comments*
(No HTML allowed)
:-) :-D :biggrin: :-P ;-) 8-) :-( :mad: |-| :oops: :-/ :-| :roll:
bold italic quote code
Code* captcha Enter the code you see in the image
* required fields