Solved

Haskell list of string problem

Posted on 2010-11-18
6
308 Views
Last Modified: 2012-05-10
Hello,

What is the best way to define a function that takes a list of words and returns a single piece of text made up the words with a space between each?

Regards
0
Comment
Question by:SSupreme
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 3

Assisted Solution

by:kraiven
kraiven earned 500 total points
ID: 34163936
You probably want the fold operation i.e.

foldr (\acc s -> acc ++ " " ++ s)  "" ["1","2","3","4"]

Open in new window


produces "1 2 3 4 " as its output
0
 
LVL 16

Author Comment

by:SSupreme
ID: 34164075
Yes, it works.

can I do the same thing with this function?

 
concatos :: [[a]] -> [a]
concatos [] = []
concatos (x:t) = x ++ concatos t

Open in new window

0
 
LVL 16

Author Comment

by:SSupreme
ID: 34164084
How to add spaces?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
kraiven earned 500 total points
ID: 34164520
How about:

concatos (x:t) = x ++ " " ++ concatos t  
0
 
LVL 16

Author Closing Comment

by:SSupreme
ID: 34165525
I tried it before and it didn't compile, but I found my mistake and it's compile now.
Type should be: concatos :: [[Char]] -> String
0
 
LVL 3

Expert Comment

by:kraiven
ID: 34165547
Gotcha, I hadn't included the function definition in my test otherwise I might have picked up this error also.

Glad it's fixed.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
static class 3 86
groupSumClump challenge 9 144
mapShare challenge 13 180
Problem to Alipay 10 95
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This video teaches viewers about errors in exception handling.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question