0
votes

Hello this function should take a String and return a list of Strings split at the Char c. I should define some helper functions but currently the user must initialize args that should be hidden from them.

xs = output list, i = start index for substr, j = end index for substr

example: split "123,456,789" ',' [] 0 0

should yield ["789", "456", "123"]

split s c xs i j =
        if j == length s
        then (subStr s i j) : xs
        else if head (drop j s) == c
        then split s c (subStr s i j : xs) (j + 1) (j + 1)
        else split s c xs i (j + 1)

subStr s i j = take j(drop i s)

When i apply the function with the following args: split "123,456,789" ',' [] 0 0

I'm getting the result: ["789", "456,789", "123"]

1
well, it would be good if you used a good variable names, I'm looking it and just am confused more and more.sertsedat

1 Answers

0
votes

I already mentioned this on your other post, but the issue with this is your subStr function. If you change it to subStr s i j = take (j-i) (drop i s) it should work. And if that's all you want, great. But it could be written more clearly and easily using takeWhile, or using split from data.Text.

Also, type signatures please. (Although I do appreciate that you defined the inputs this time.) Not only do they make it easier for us to help, you can often solve your own problems in the process of figuring them out.