[Haskell-cafe] returning lists

Sebastian Sylvan sebastian.sylvan at gmail.com
Thu Dec 1 14:54:04 EST 2005


On 12/1/05, raptor <raptor at tvskat.net> wrote:
> hi,
>
> i'm having this problem, tring to implement split (for learning purposes).
> Here is one sample of my tries :
>
> split _ [] = []
> split char (x:xs)
>         | x /= char = x : split char xs
>         | otherwise = []
>
>
> it is ok i.e. it returns the first of the splits, but I want to get
> all of the results.
>
>
> str = "testingxsplitxtoxseexhowxitxwork"
>
> *Main> split 'x' str
> "testing"
>
> I want :
> ["testing","split",...]
>
>
> How do i do this.
>

A good start is to write a function which returns the first split, as
well as the remainder of the string as a tuple.
Then you can use this function over and over on the remainder of each
call until it is "".

/S
--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell-Cafe mailing list