- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 185 Articles for Haskell
![Akhil Sharma](https://www.tutorialspoint.com/assets/profiles/525598/profile/60_3453735-1664185297.jpg)
1K+ 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 isOdd n = isEven (n - 1)) function. And in the second example, we are going to use (isEven n = n `mod` 2 == 0) function. Method 1: Checking whether a number is even or odd using isEven and isOdd function In this method, the isEven and isOdd functions ... Read More
![Akhil Sharma](https://www.tutorialspoint.com/assets/profiles/525598/profile/60_3453735-1664185297.jpg)
137 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 == y then '0' else if x == '0' then '1' else '0'])). Where as in the second example, we are going to use two helper functions along with recursion. Method 1: Converting the Binary number to Gray Code using recursion In this method, the grayCode function is defined to ... Read More
![Akhil Sharma](https://www.tutorialspoint.com/assets/profiles/525598/profile/60_3453735-1664185297.jpg)
209 Views
In Haskell, we will convert the decimal number to binary by using recursion and tail-recursion. In the first example, we are going to use base case, (decToBin 0 = "0" and decToBin 1 = "1") and recursive case, (decToBin n = decToBin (n `div` 2) ++ show (n `mod` 2)). Whereas in second example, we are going to use tail-recursive function. Algorithm Step 1 − The user defined, decToBin function is defined with base and recursive case as, Example 1 and 2 − decToBin 0 = "0" decToBin 1 = "1" decToBin n = decToBin ... Read More
![Akhil Sharma](https://www.tutorialspoint.com/assets/profiles/525598/profile/60_3453735-1664185297.jpg)
449 Views
In Haskell, we can find the the GCD of two given numbers by using recursion along with gcd function and tail-recursion. In the first and second examples, we are going to use base case, (gcd a 0 = a) and recursive case, gcd a b = gcd b (a `mod` b)) and in the third example, we are going to use tail-recursive function. In the following examples we define a gcd function that takes two Int arguments a and b. The function uses pattern matching to handle two cases − If b is 0, the function returns a ... Read More
![Akhil Sharma](https://www.tutorialspoint.com/assets/profiles/525598/profile/60_3453735-1664185297.jpg)
84 Views
In Haskell, we will find the the LCM of two given numbers by using recursion along with gcd and max function. In the first example, we are going to use (gcd) and (lcmOfTwoNumbers) function and in the second example, we are going to use (lcm) and (lcmOfTwoNumbers a b = lcm a b (max a b)) function. Algorithm Step 1 − The Prelude library is imported for hiding the gcd function. Step 2 − Define two user-defined functions - gcd and lcmOfTwoNumbers , Step 3 − Program execution will be started from main function. The main() function has whole ... Read More
![Akhil Sharma](https://www.tutorialspoint.com/assets/profiles/525598/profile/60_3453735-1664185297.jpg)
882 Views
In Haskell, we can find the given number is PRIME or not by using recursion along with helper function. In the first example, we are going to use (isPrime n | n Bool isPrime n | n Integer -> Bool isPrimeHelper n d | d > (n `div` 2) = True | n `mod` d == 0 = False | otherwise = isPrimeHelper n (d + 1) main :: IO () main = do let ... Read More
![Akhil Sharma](https://www.tutorialspoint.com/assets/profiles/525598/profile/60_3453735-1664185297.jpg)
255 Views
In Haskell, we can find reverse of a given number by using recursion along with helper function. In the first example, we are going to use (reverseNumHelper n rev) function and in the second example, we are going to use (reverseNum n | n < 10 = n| otherwise = (n `mod` 10) * (10 ^ numDigits (n `div` 10)) + reverseNum (n `div` 10)) function. Finding the reverse of a given number using recursion using the helper function In this method, the reverseNumHelper function takes two arguments: n and rev. n is the number to reverse and rev is ... Read More
![Akhil Sharma](https://www.tutorialspoint.com/assets/profiles/525598/profile/60_3453735-1664185297.jpg)
189 Views
In Haskell, we can display Prime Numbers between Two Intervals using user-defined functions and list comprehension. In the first example, we are going to use (isPrime and primesInRange) user-defined functions and in the second example, we are going to use list comprehension. Algorithm Step 1 − The Data.List library is imported. Step 2 − The user-defined isPrime function is defined. Step 3 − Program execution will be started from main function. The main() function has whole control of the program. Step 4 − The variables named, “lower” and “upper” are being initialized. It will hold the range between which ... Read More
![Akhil Sharma](https://www.tutorialspoint.com/assets/profiles/525598/profile/60_3453735-1664185297.jpg)
97 Views
In Haskell, we can useuser-defined functions and using recursion. In the first example we are going to use (user-defined, isArmstrong and armstrongInRange) function and in the second example, we are going to use recursion with base and recursive case. Algorithm Step 1 − The user-defined isArmstrong function is defined 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 variables named, “lower” and “upper” are being initialized. It will hold the range between which the armstrong numbers ... Read More
![Akhil Sharma](https://www.tutorialspoint.com/assets/profiles/525598/profile/60_3453735-1664185297.jpg)
116 Views
In Haskell, we can Display Prime Numbers Between Intervals using user-defined function along with filter function and recursion. In the first example we are going to use user-defined, (isPrime) function with (primeInRange a b = filter isPrime [a..b] ) function and in the second example, we are going to use recursion with base and recursive case. Algorithm Step 1 − The Data.List library is imported. Step 2 − The user-defined isPrime function is defined as, Step 3 − Program execution will be started from main function. The main() function has whole control of the program. It is written as ... Read More