MahmutBulut
MahmutBulut

Reputation: 53

Convert a List contains Tuples to formatted String

I have [(Double, Double)] returned list and I want to format it and return it like this String

"(Double, Double)"

values must convert to String mentioned above line as Double.

If there is more than one value in the list, it should be formatted as:

"(Double, Double), (Double, Double), ..., (Double, Double)"

Upvotes: 0

Views: 441

Answers (3)

efie
efie

Reputation: 544

format yourList = intercalate ", " $ map show yourList

Upvotes: 1

Gabriella Gonzalez
Gabriella Gonzalez

Reputation: 35089

If you actually want to print the specific values of the Doubles, then efie gave the correct answer. However, if you only want to show the string "Double", then you would use the following answer:

format = intercalate ", " . map (const "(Double, Double)")

Upvotes: 1

dflemstr
dflemstr

Reputation: 26167

You can use the native Show instance of the list:

showPairSequence :: [(Double, Double)] -> String
showPairSequence = init . tail . show

Upvotes: 0

Related Questions