Akhil Sharma has Published 507 Articles

Haskell Program to Convert String to an Array

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 14:56:48

2K+ Views

In Haskell, we will convert String to an Array by using listArray and intersperse functions. In the first example, we are going to use (stringToArray s = listArray (0, length s - 1) s) function and in the second example, we are going to use (stringToArray s = s) function. ... Read More

Haskell Program to Convert Character to String

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 14:55:14

2K+ Views

In Haskell, we can convert Character to String by using user-defined function, show function, list comprehension and (:[]) notation. In the first example, we are going to use (charToString c = [c]) function and in the second example, we are going to use (charToString c = show c) function. Where ... Read More

Haskell Program to Check Whether an Alphabet is Vowel or Consonant

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 12:40:40

683 Views

We can use elem function in Haskell to check whether the given alphabet is vowel or consonant. In the first example, we are going to use (isVowel c = c `elem` "aeiouAEIOU") function. And in other examples, we’re going to use elem function along with certain if-else statements, nested conditions ... Read More

Haskell Program to Call One Constructor from Another

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 12:26:32

297 Views

In Haskell, we will call one constructor from another by using user-defined function. In the first example, we are going to use (newPerson name = Person name 10) constructor and in the second example, we are going to use (newPerson n a = Person { name = n, age = ... Read More

Haskell Program to get total Bits Required for the Given Number using Library Function

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 12:22:59

177 Views

Haskell has internal function like finiteBitSize, ceiling, logBase, length and showIntAtBase that can be used to get total bits required from the given number. In the first example, we are going to use (bits = finiteBitSize (fromIntegral x :: Int)) function and in the second example, we are going to ... Read More

Haskell Program to Calculate the Logarithm Gamma of the Given Number

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 12:20:36

199 Views

In Haskell, we will calculate the logarithm gamma of the given number by using Stirling’s approximation and Lanczos appromixation formula. In the first example, we are going to use Stirling’s approximation with (s = foldr (\(c, q) acc -> c + (q / (x + acc))) 0 (zip (tail ... Read More

Haskell Program to Round a Number to n Decimal Places

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 11:58:06

2K+ Views

In Haskell, we can use round, printf and truncate functions to round a number to n decimal places. In the first example, we are going to use (roundTo n x = (fromInteger $ round $ x * (10^n)) / (10.0^^n)) function and in the second example, we are going to ... Read More

Golang program to get key based on value from the hash collection

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 13:05:27

653 Views

In golang, we can use hashmap to perform various operations like deleting, updating, and storing the values in the hash collection. In this article, we are going to understand get key based on a value from the hash collection using two different examples. In the first example, we will use ... Read More

Haskell Program to Find the Product of Two Numbers Using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:43:58

709 Views

In Haskell, we can find the Product of Two Numbers by using recursion along with recursive repeated addition. In the first example we are going to use (product' x y | y == 0 = 0 | y == 1 = x | otherwise = x + product' x (y-1)) ... Read More

Haskell Program to Find Sum of Digits of a Number using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:43:33

752 Views

In Haskell, we can find Sum of Digits of a Number by using recursion along with mod, div and other helper functions. getCurrentTime and NominalDiffTime function. In the first example we are going to use (sumOfDigits n | n < 10 = n | otherwise = (n `mod` 10) ... Read More

Advertisements