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.