Akhil Sharma has Published 671 Articles

Haskell Program to convert long type variables into int

Akhil Sharma

Akhil Sharma

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

163 Views

In Haskell, we can use fromIntegral function along with toInteger and truncate function, div and mod functions to convert long type variable into int. In the first example, we are going to use ( let intVar = fromIntegral longVar :: Int) and in the second example, we are going ... Read More

Haskell Program to convert int type variables to char

Akhil Sharma

Akhil Sharma

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

972 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

536 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

213 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

361 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

Haskell Program to convert Binary to Decimal

Akhil Sharma

Akhil Sharma

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

588 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

595 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

422 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 successor of an integer number using library function

Akhil Sharma

Akhil Sharma

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

271 Views

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

128 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

Advertisements