[Haskell-beginners] Defining 'words' in terms of 'span'

Daniel Fischer daniel.is.fischer at web.de
Tue Mar 16 14:36:04 EDT 2010


Am Dienstag 16 März 2010 18:23:33 schrieb Ozgur Akgun:
> You might start with looking into
> span<http://haskell.org/ghc/docs/latest/html/libraries/base-4.2.0.0/Prel
>ude.html#v:span> .
>
> span :: (a -> Bool) -> [a] -> ([a], [a])
>

And then, using span, write a function that splits the first word off a 
String. And a function to use when the String doesn't start with a word 
(like "", " made glorious summer by this son of York.", "2+3", ...).

>
> For example try these,
>
> span ('a'==) "abcd"
> span ('a'==) "aaabcd"
> span ('c'==) "abcd"
> span ('c'/=) "abcd"
> span ('c'/=) "abcdcdcd"
>
> On 16 March 2010 17:08, Roger Whittaker <roger at disruptive.org.uk> wrote:
> > I found some exam papers linked from this page:
> > http://www.cs.chalmers.se/Cs/Grundutb/Kurser/d1pt/d1pta/external.html
> >
> > And I have been trying some questions from them.
> >
> > I'm currently baffled by question 2(b) on this one:
> > http://www.cs.chalmers.se/Cs/Grundutb/Kurser/d1pt/d1pta/tenta2000-04.p
> >s
> >
> >  A word is a sequence of alphabetic characters, which you can
> > recognise using the standard function
> >
> >  isAlpha :: Char -> Bool
> >
> >  Using span, define a function words :: String -> [String] which
> >  finds a list of the words occurring in a string. For example,
> >
> >  words "Now is the winter of our discontent!"
> >    == ["Now","is","the","winter","of","our","discontent"]
> >
> >  words "2+3" == []
> >
> >  words "1 by 1" == ["by"]
> >
> > Can anyone give me a clue how to start?
> >
> >
> >
> >
> > --
> > ========================
> > Roger Whittaker
> > roger at disruptive.org.uk
> > http://disruptive.org.uk
> > ========================
> > _______________________________________________
> > Beginners mailing list
> > Beginners at haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners



More information about the Beginners mailing list