# [Haskell-cafe] Hi I need help for very simple question!

Taillefer, Troy (EXP) troy.taillefer at lmco.com
Fri Mar 2 12:35:12 EST 2007

```Hi there

1. First of all never forget your base case for exiting your recursion
2. you need to break up the problem like so

import Char

-- get the first word
word :: String -> String
word [] = []
word ( x : x1 : xs )
| isSpace x = []
| isSpace x1 = x : []
| otherwise = x : x1 : word(xs)

-- get everything but the first word
rest :: String -> String
rest [] = []
rest ( x : x1 : xs )
| isSpace x = x1 : xs
| isSpace x1 = xs
| otherwise = rest(xs)

intoWords :: String -> [ String ]
intoWords [] = []
intoWords ws = word(ws) : words( rest(ws) ) -- glue the first word and
call recursively on the rest

3. Assuming this wasn't for a homework assignment or curiosity the you
can use the standard function Prelude.words to do this

Troy

-----Original Message-----
Sent: March 2, 2007 11:23 AM
Subject: [Haskell-cafe] Hi I need help for very simple question!

I have problem implementing one function. I think my idea is write but I
have minor mistakes which I cannot get right since I progrem Haskell
from very recently. No the function is called intoWords and has to take
a string of any size and kind of characters.No I have to produce as
output a list of strings.To have a rule which defines an element from
the list is the space character which can also be included in the
string.So what i think should be smth like. intoWord Hello my name is
Smart should produse a list looking like [Hello,my,name,is,Smart] Now I
tried to do it recucively to take the string and checks if an element is
white space in the list using the isSPace build in function. This is my
to produce a base case for my recursion.

import Char

intoWords ::String -> [String]

intoWords  (x:xs)
|isSpace x = intoWords xs
|otherwise = xs

Thanks in advance for any suggestions. I really want to understand this
bloody function couse I've been tring for a week now and I have tried so
many ways to produce it that now I am fed up with it and I want to know
how should it work since I am curious now.

--
View this message in context:
http://www.nabble.com/Hi-I-need-help-for-very-simple-question%21-tf33344
86.html#a9272506