function - Haskell: Adding commas when printing a list of integers -


with input being:

"i am, , (765) not spam. abc2. abc3." 

my code makes output of:

abc 2 1 2 , 2 2 1 2 2 not 2 spam 2 1 

where each word listed along line number appears on.

question: how print statement below commas between line numbers so:

abc 2 1,2 , 2 2 1,2 2 not 2 spam 2 1 

here code have takes list tuples formatted

[([1, 2], "a"), ([1], "b"), ([1], "c"), ([2], "dd")]

and prints current output listed above:

combineints listtuple = map f $ groupby ((==) `on` fst) $ sortby (compare `on` fst) $ map swap listtuple     f xs@(x:_) = (map snd xs, fst x)  printlisttuples listtuple = unlines [ ys ++ " " ++ unwords (map show x) | (x, ys) <- listtuple ] 

if can figuring out how commas in between line numbers useful , more readable.

there's easy way, , there's hard way. easy way use show instance lists , couple simple list functions. other simple way use 1 list function. cn see how? harder bit more educational) way write yourself. can come base cases , recursive case?


Comments