## Haskell Program to Print Inverted Star Pattern Updated on 28-Mar-2023 14:36:40
In Haskell, to print Inverted star pattern we will be using mapM_, reverse, unlines and replicate functions. In the first example, we are going to use ( invertedStarPattern n = mapM_ putStrLn (reverse [replicate i '*' | i

## Haskell Program to Print Diamond Star Pattern Updated on 28-Mar-2023 14:34:57

## Haskell Program to Print Left Triangle Star Pattern Updated on 28-Mar-2023 12:43:39
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 Triangle Star Pattern using mapM_ function under main function In this method, we first define the number of rows of the triangle as n (in this case, n = 5). We then use a list comprehension to generate a list of strings, where each string is a row of the ... Read More

## Haskell Program to Check Whether an Alphabet is Vowel or Consonant Updated on 28-Mar-2023 12:40:40
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 and guards. Algorithm Step 1 − The data type ‘Person’ is defined with two fields name and an age. Step 2 − The isVowel function is defined using elem function as Step 3 − The program execution will be started from main function. The main() function has whole control ... Read More

## Haskell Program to Call One Constructor from Another Updated on 28-Mar-2023 12:26:32
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 = a }) constructor. In the third example, we are going to use (clonePerson p = p { name = name p ++ " clone" }) constructor and in the fourth example, we are going to use (clonePerson p = p { name = name p ++ " clone" }) ... Read More

## Haskell Program to get total Bits Required for the Given Number using Library Function Updated on 28-Mar-2023 12:22:59

## Haskell Program to Round a Number to n Decimal Places Updated on 28-Mar-2023 11:58:06
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 use (roundTo n x = read $printf ("%." ++ show n ++ "f") x) function.In the third example, we are going to use (roundTo n x = fromIntegral (truncate$ x * 10^n) / 10^n). Algorithm Step 1 − The roundTo function is defined using round function Step ... Read More