concat two integers haskell
In Haskell, you can concatenate two integers by converting them to strings using the show
function, concatenating the strings using the ++
operator, and then converting the resulting string back to an integer using the read
function. Here's an example:
concatenateIntegers :: Int -> Int -> Int
concatenateIntegers x y = read (show x ++ show y)
This function takes two integers x
and y
as input and returns their concatenation as an integer. The show
function converts each integer to a string, the ++
operator concatenates the strings, and the read
function converts the resulting string back to an integer.
You can use this function to concatenate two integers in Haskell. For example:
main :: IO ()
main = do
let concatenated = concatenateIntegers 123 456
print concatenated
This will output 123456
, which is the concatenation of 123
and 456
.