I want to concatenate strings in Haskell and also integers from function like this:
arc 13 34 234 3
13 34 234 3 will be arguments of arc function and I want output like
"arc(13, 34, 234, 3)"
as a String how can I implement this?
How can list of numbers could be concatenated into a string? Looks like some [Int] -> String
function can help here.
> concat . intersperse ", " . map show $ [13, 34, 234, 3]
"13, 34, 234, 3"
So, let's add some brackets and "arc" to that String.
import Data.List (intersperse)
arc :: [Int] -> String
arc nums = "arc(" ++ (concat . intersperse ", " . map show $ nums) ++ ")"
And we get the answer.
> arc [13, 34, 234, 3]
"arc(13, 34, 234, 3)"
If you are really need function with signature like Int -> Int -> Int -> Int -> String
:
arc' :: Int -> Int -> Int -> Int -> String
arc' a1 a2 a3 a4 = "arc(" ++ (concat . intersperse ", " . map show $ [a1,a2,a3,a4]) ++ ")"
> arc' 13 34 234 3
"arc(13, 34, 234, 3)"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With