[Haskell-beginners] Re: Defining 'words' in terms of 'span'
Roger Whittaker
roger at disruptive.org.uk
Tue Mar 16 18:02:01 EDT 2010
Thanks for the suggestions - I think the idea was that you had to
use a recursive definition in terms of span.
I eventually did this, but didn't feel it was at all nice or
elegant:
import Data.Char
mywords :: [Char] -> [[Char]]
mywords l | ((snd (span isAlpha l)) == "" && (fst (span isAlpha l)) == "") = []
| ((snd (span isAlpha l)) == "" && (fst (span isAlpha l)) /= "") = [fst (span isAlpha l)]
| (fst (span isAlpha l)) == "" = mywords (tail (snd (span isAlpha l)))
| otherwise = [fst (span isAlpha l)] ++ mywords (tail (snd (span isAlpha l)))
--
========================
Roger Whittaker
roger at disruptive.org.uk
http://disruptive.org.uk
========================
More information about the Beginners
mailing list