Akhil Sharma has Published 507 Articles

Haskell Program to convert Binary to Decimal

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:03:39

920 Views

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

Haskell Program to convert Decimal to Binary

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:02:36

1K+ Views

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

Haskell Program to convert Decimal to Hexadecimal

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 15:01:44

687 Views

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

Haskell Program to get the predecessor of an integer number using library function

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 14:59:41

297 Views

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

Haskell Program to get the Division and Remainder using library function

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 14:56:52

2K+ Views

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

Haskell Program to get the real part from a Complex number

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 14:55:40

205 Views

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

Haskell Program to check a given number is finite or not

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 14:54:26

228 Views

In Haskell, we can use isIEEE, isInfinite and isNaN functions to check whether a given number is finite or not. In the first example we are going to use (isIEEE n) function with if-else statement and in the second example, we are going to use (isInfinite n) function. And ... Read More

Haskell Program to get the numerator from a rational number

Akhil Sharma

Akhil Sharma

Updated on 13-Mar-2023 14:53:00

273 Views

In Haskell, we can use numerator, div, quot and gcd functions to find the numerator from a given rational number. In the first example we are going to use numerator (r) function and in the second example, we are going to use (n `div` gcd n d) function. And in ... Read More

Haskell Program to calculate the value from the given fraction and exponent

Akhil Sharma

Akhil Sharma

Updated on 01-Mar-2023 18:01:20

314 Views

This haskell tutorial will help us in calculating the value from the given fraction and exponent of a number. To find this, the input is taken as fraction and exponent, and its corresponding value is computed. Algorithm Step 1 − The “Data.Ratio” is imported to work over fractions. ... Read More

Golang program to include a module inside the class

Akhil Sharma

Akhil Sharma

Updated on 01-Mar-2023 12:00:19

184 Views

In Go programming language, a new module is initiated using init command after which we can import other modules in our code. There is no concept of class in Go, only structs are used. In this article, we will use one example to include a module inside the class. In ... Read More

Advertisements