In Haskell, we can convert Boolean to String by using user-defined function along with guards and if-else statements. In the first example, we are going to use (boolToString True = "True" and boolToString False = "False") function and in the second example, we are going to use (boolToString b | b = "True" | otherwise = "False") as function definition. And in the third example, we are going to use (boolToString b = if b then "True" else "False"). Algorithm Step 1 − Define the Boolean function Step 2 − Program execution will be started from main function. ... Read More
In Haskell, we can use functions like foldl, recursion, and list comprehension to convert a binary number to decimal. In the first example, we are going to use (binToDec = foldl (\acc x -> 2*acc + digitToInt x) 0) and in the second example, we are going to use base case, (binToDec "" = 0) and recursive case, (binToDec (x:xs) = 2 * binToDec xs + digitToInt x) function. And in the third example, we are going to use (binToDec = sum . zipWith (\x y -> 2^x * digitToInt y) [0..] . reverse). Algorithm Step 1 − ... Read More
In the post-pandemic period, digital marketing has established itself as the most effective strategy. Traditional marketing is being put on hold as consumers and businesses turn to the Internet as their preferred shopping venue. As an outcome, brands are depending more than ever on digital strategy. His most recent CMO poll indicates that 56% of businesses are altering their business strategies to capitalize on digital advances. The global transition to digital interactions is encouraging companies of all sizes to consider marketing online, which will make the field of digital marketing more challenging than ever in 2021. Keeping an eye on ... Read More
In Haskell, we will convert Decimal to Binary by using reverse function , tail recursion, and divMod function. In the first example, we are going to use (decToBin n | n < 0 = error "Input must be non-negative" | n == 0 = "0" | otherwise = reverse $ decToBin' n) and in the second example, we are going to use (binDigits 0 = "" and binDigits n = let (q, r) = n `divMod` 2 in show r ++ binDigits q) function. Method 1: Using reverse function and tail recursion In ... Read More
In Haskell, we can use intToDigits, showIntAtBase and format functions to convert a decimal to Hexadecimal number. In the first example, we are going to use (decToHex n = reverse (hexChars n) where hexChars 0 = "" and hexChars x = intToDigit (x `mod` 16) : hexChars (x `div` 16)) and in the second example, we are going to use (decToHex n = showIntAtBase 16 intToDigit n "") function. In the third example, we are going to use (decToHex n = printf "%X" n) function. Method 1: Using reverse and intToDigits functions In this method, the Data.Char module is ... Read More
In Haskell, we can get the the successor of an integer number using library function like succ, addition and fromMaybe function. In the first example, we are going to use (succ number) function and in the second example, we are going to use addition while in third example, we are going to use (fromMaybe 0 (succMaybe x)) function. Algorithm Step 1 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. It calls the succ function with the value and prints its ... Read More
In Haskell, we can use library function like pred, subtraction and fromMaybe to get the predecessor of an integer number. In the first example, we are going to use (pred number) function and in the second example, we are going to use subtraction while in third example, we are going to use (fromMaybe 0 (predMaybe x)) function. Algorithm Step 1 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. It calls the pred function with the value and prints its predecessor ... Read More
In Haskell, we have library function like, by using Mod and Rem function to check if the given number is odd or not. In the first example, we are going to use (isOdd n = n `mod` 2 /= 0) function and in the second example, we are going to use (isOdd n = (n `rem` 2) == 1) function. Algorithm Step 1 − The isOdd function is defined using mod function as, isOdd n = n `mod` 2 /= 0. Step 2 − Program execution will be started from main function. The main() function has ... Read More
In Haskell, we can use divMod and quotRem functions to get the division and remainder of a given number. In the first example, we are going to use (divMod x y) function and in the second example, we are going to use (quotRem 20 7) function. Algorithm Step 1 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. Step 2 − The variables named, “x” and “y” are being initialized. The interal function will divide them by taking them as argument. Step ... Read More
In Haskell, we can use realPart function and pattern matching to get the real part from a complex number. In the first example we are going to use (realPart c) function and in the second example, we are going to use patter matching as (x:+_) = c. Algorithm Step 1 − The Data.Complex module is imported to work over the complex numbers. Step 2 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. Step 3 − The variable named, “c” is being ... Read More