
On Fri, 06 Aug 2010 02:44:26 +0200
Jürgen Doser
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?
you are a good teacher, jurgen! here's what i came up with: br [] = [] br ss = fst (tup) : br (tail (snd tup)) where tup = break eqD ss now this works great for let s = "zaoeu%aeuasnt%staashaeu%nthdanoe%nthd%" but i get a *** Exception: Prelude.tail: empty list i found a neat way to explore recursion on ghci like this Prelude> let s = "aoeu%snthi%ashuet" Prelude> break (=='%') s ("aoeu","%snthi%ashuet") Prelude> break (=='%') (tail (snd it)) ("snthi","%ashuet") Prelude> break (=='%') (tail (snd it)) ("ashuet","") Prelude> break (=='%') (tail (snd it)) *** Exception: Prelude.tail: empty list of course this is the problem i'm having in that i'm forced to take the tail of an empty list at the end. correcting it by sticking on a delimiter doesn't seem to be the right thing to do though. so there must be another way to deal with this. hmmm. -- In friendship, prad ... with you on your journey Towards Freedom http://www.towardsfreedom.com (website) Information, Inspiration, Imagination - truly a site for soaring I's