## DEV Community is a community of 610,973 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

loading...

# Palindrome Program using Haskell

I try to learn the syntax of different programming languages. In this blog I have written the program to find whether a number is a palindrome or not using 6 different programming languages. These languages include C, C++, Java, Python, Perl, and Ruby.

I tried learning functional programming and wrote a program to find whether a number is a palindrome number using Haskell. The program for finding palindrome using Haskell is given below.

Functional programming is a programming paradigm in which we try to bind everything in pure mathematical functions style. It is a declarative type of programming style. Its main focus is on “what to solve” in contrast to an imperative style where the main focus is “how to solve”.

``````
-- Main function which takes input and prints palindrome or not by using the function palindrome to check
main :: IO ()
main = do
print "Enter a number: "
inputStr <- getLine
let input = read inputStr :: Integer
if palindrome input then
print \$ show input <> " is a palindrome number"
else
print \$ show input <> " is not palindrome number"

-- palindrome function which checks whether the number is a palindrome by comparing with the reverse of the number
palindrome :: Integer -> Bool
palindrome x = reversal x == x

-- reversal function for calculating the reverse of the number
reversal :: Integral a => a -> a
reversal = go 0
where go a 0 = a
go a b = let (q,r) = b `quotRem` 10 in go (a*10 + r) q
``````

## Discussion (0)
{"ft_lang_label":"__label__en","ft_lang_prob":0.8037436,"math_prob":0.88364214,"size":1436,"snap":"2021-04-2021-17","text_gpt3_token_len":324,"char_repetition_ratio":0.1773743,"word_repetition_ratio":0.06949807,"special_character_ratio":0.24094708,"punctuation_ratio":0.08846154,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97865564,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-04-21T04:53:12Z\",\"WARC-Record-ID\":\"<urn:uuid:7136887a-5b76-4556-8c1b-9ada392ba404>\",\"Content-Length\":\"102060\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:91f64175-f7bf-4771-a1c0-cc419727ea39>\",\"WARC-Concurrent-To\":\"<urn:uuid:4346694a-2957-4707-a9e9-e874a7293c63>\",\"WARC-IP-Address\":\"151.101.2.217\",\"WARC-Target-URI\":\"https://dev.to/amananandrai/palindrome-program-using-haskell-4g0a\",\"WARC-Payload-Digest\":\"sha1:S4T3CNKHQTWJVJLXEBA3K5PSWXIV5CA4\",\"WARC-Block-Digest\":\"sha1:C3S24C6MMK2WUDTRJV6NTXGMMFHBLTJA\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-17/CC-MAIN-2021-17_segments_1618039508673.81_warc_CC-MAIN-20210421035139-20210421065139-00008.warc.gz\"}"}