Akhil Sharma has Published 671 Articles

Haskell Program to Print Mirror Lower Star Triangle Pattern

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 12:48:38

91 Views

In haskell, we can use unlines and replicate functions to print mirror lower star in triangle pattern. In the first example, we are going to use ( mirrorLowerTriangle n = unlines [replicate i '*' | i

Haskell Program to Print Downward Triangle Star Pattern

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 12:45:23

113 Views

In Haskell, to print the downward traingle star pattern we will be using mapM_, replicate and unlines functions. In the first example, we are going to use ( mapM_ putStrLn $ map (concat . flip replicate "*") rows) function defined under main function and in the second ... Read More

Haskell Program to Print Left Triangle Star Pattern

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 12:43:39

203 Views

In Haskell, to print the Left Triangle Star Pattern we will be using mapM_ function, replicate function and recursion. In the first example, we are going to use ( mapM_ putStrLn [replicate i '*' | i > putStrLn (replicate n '*') else return ()) function. Method 1: Printing Left ... 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

275 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

155 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

51 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

91 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

755 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

355 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 Sum of N Numbers Using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:44:50

528 Views

In Haskell, we can find Sum of N Numbers by using recursion, tail-recursion and fold-recursion. In the first example we are going to use base case, (sum_n [] = 0) and recursive case, (sum_n (x:xs) = x + sum_n xs)) and in second example, we are going to use, tail-recursion. ... Read More

Advertisements