Akhil Sharma has Published 507 Articles

Haskell Program to Calculate the Execution Time of Methods

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:42:53

1K+ Views

In Haskell, we can use getCurrentTime and NominalDiffTime functions to calculate the Execution Time of Methods. In the first example we are going to use (startTime

Haskell Program to Reverse a Sentence Using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:39:48

973 Views

In Haskell, we can reverse a Sentence by using recursion along with concatenation and also by using list comprehension. In the first example we are going to use recursion along with base and recursive case and in the second example, we are going to use concatenation as ((last sentence) : ... Read More

Haskell Program to Find G.C.D Using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:32:34

240 Views

In Haskell, we can find G.C.D by using recursion and also by using recursive case statements. In the first example we are going to use recursion along with base and recursive case and in the second example, we are going to use (case (x, y) of) statement. Algorithm Step ... Read More

Haskell Program to Find Factorial of a Number Using Recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:31:56

2K+ Views

In Haskell, we Find Factorial of a Number Using Recursion by using recursion along with foldl and product function. In the first example we are going to use recursion along with base and recursive case and in the second example, we are going to use factorial n = foldl (*) ... Read More

Haskell Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:30:06

258 Views

In Haskell, we will Check Whether a Number can be Expressed as Sum of Two Prime Numbers by using user-defined functions. In the first example we are going to use (isPrime) function along with primeSum function and in the second and third example, we are going to use (isPrime) function ... Read More

Haskell Program to Check if An Array Contains a Given Value

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 11:11:52

1K+ Views

In Haskell, we will Check if An Array Contains a Given Value by using recursion and foldr & elem functions. In the first example, we are going to use base and recursive cases and in the second example, we are going to use (containsValue x = foldr (\y acc -> ... Read More

Haskell Program to Check Whether a Character is Alphabet or Not

Akhil Sharma

Akhil Sharma

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

1K+ Views

In Haskell, we will Check Whether a Character is Alphabet or Not by using relational operator comparison, if-else statements and Data. Char module. In the first example, we are going to use (isAlpha c | c >= 'a' && c = 'A' && c = 'a' && c = 'A' ... Read More

Haskell Program to Check Whether a Number is Positive or Negative

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 10:59:51

2K+ Views

In Haskell, we can Check Whether a Number is Positive or Negative by using comparison operators and if-else statements. In the first example, we are going to use (isPositive n | n > 0 = "Positive" | n == 0 = "Zero" | otherwise = "Negative") function. And in the ... Read More

Haskell Program to Check Whether a Number is Even or Odd

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 10:59:02

3K+ Views

In Haskell we have isEven, isOdd and mod functions that can be used for checking whether a given number is even or odd. In the first example, we are going to use (isEven 0 = True and isEven n = isOdd (n - 1)) and (isOdd 0 = False and ... Read More

Haskell Program to convert the Binary number to Gray code using recursion

Akhil Sharma

Akhil Sharma

Updated on 27-Mar-2023 10:58:18

265 Views

In Haskel we can use recursion along with helper function toconvert the Binary number to Gray code. In the first example, we are going to use base case, (grayCode "" = "" and grayCode [x] = [x]) and recursive case, grayCode (x:y:xs) = x : grayCode (xs ++ [if x ... Read More

Advertisements