Akhil Sharma has Published 507 Articles

Haskell Program to Display Prime Numbers Between Intervals Using Function

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:26:15

248 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 ... Read More

Haskell Program to Make a Simple Calculator Using switch...case

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:25:32

1K+ Views

In this article we are going to learn how to make a simple calculator in Haskell using switch…case. In the first example, we are going to use case statements with different operators and in the second example, we are going to use map of functions as (fromList [('+', (+)), ('-', ... Read More

Haskell Program to Display Factors of a Number

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:23:45

923 Views

In Haskell, we can list comprehension, filter function and recursion to display factors of a number. In the first example we are going to use (factors n = [x | x n `mod` x == 0) [1..n]) function. And in third example, we are going to use recursion with ... Read More

Haskell Program to Display Armstrong Numbers Between Intervals Using Function

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:22:33

205 Views

Haskell has functions like higher order and filter, that can be used for getting the Armstrong number between two given internvals. In the first example we are going to use (isArmstrong and armstrongInRange function with higher order) and in the second example, we are going to use (filter isArmstrong ... Read More

Haskell Program to get the Magnitude of the given number

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:20:47

359 Views

Haskell has internal functions like negate, abs and signum functions that can be used to get magnitude of the given number. In the first example we are going to use (negate n) function and in the second example, we are going to use (abs) function. In third example, we are ... Read More

Haskell Program to convert int type variables to long

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:16:11

357 Views

In Haskell, we can use internal functions like fromIntegral intToLong and toInteger function and toEnum to convert int type variable to long. In the first example, we are going to use (let longVar = fromIntegral intVar :: Int64) and in the second example, we are going to use (intToLong = ... Read More

Haskell Program to convert int type variables to char

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:12:52

2K+ Views

In Haskell, we will convert int type variables to char by using user-defined function using chr function, toEnum function and list indexing. In the first example, we are going to use (intToChar I | i >= 0 && i = 0 && i = 0 && i = 0 && ... Read More

Haskell Program to create Case statement

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:10:54

1K+ Views

In Haskell, we can use pattern matching, digitToInt, reads and a user-defined functions to convert char-type variables to int. In the first example, we are going to use cases for matching the pattern and in the second example, we are going to use (charToInt c = if isDigit c then ... Read More

Haskell Program to convert Binary to Octal

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:07:42

349 Views

In Haskell, we can use the user-defined function, Folder, reverse and helper function to convert binary to octal number. In the first example, we are going to use (binaryToOctal binary = showOct decimalValue "" where decimalValue = foldl (\acc x -> acc * 2 + digitToInt x) 0 binary) function. ... Read More

Haskell Program to Convert Boolean to String

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:06:04

619 Views

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 | ... Read More

Advertisements