[Haskell-beginners] Re: mayBe stuck

Jürgen Doser jurgen.doser at gmail.com
Thu Aug 5 20:44:26 EDT 2010


El jue, 05-08-2010 a las 17:08 -0700, prad escribió:
>
> i was wanting to do something like keep pulling characters and make a
> new string until the delimiter was found

"keep pulling ... until the delimiter was found" sounds suspiciously
like takeWhile and friends (like break, see below).

> fn cs = [x | x <- cs, x /= '%'] : []

This doesn't split, it just filters. In particular, you have no way of
knowing where in the string elements where discarded.

> but can't figure out how to use this idea to actually cause splitting
> into [String]

Neither do I :)

> i also explored break and splitAt, but haven't quite worked out a
> mechanism to use those, yet.

break is exactly what I would use. The only problem is that break will
only look for the first delimiter match. To get all the matches, you
will have to get the recursion right...

For practice purposes, in particular for getting used to recursion, it
might also be useful to write the function without any help of library
functions, traversing the string using direct recursion only. For every
character you encounter, what do you have to do in each case?

	Jürgen




More information about the Beginners mailing list