I’m having trouble getting this started, as in, I’m not sure what is exactly happening with this function. What it’s supposed to do is take in 2 parameters, a character, and a string, then output a list of strings that are separated by that character.
For example,
break ',' "abc,def,ghi"
should output [“abc”,”def”,”ghi”]
I am given the code, and I’m supposed to fill in the “?”s
break ? [] = ?
break n xs = brk n xs ?
where
brk n xs acc
| xs == [] = ?
| n == ? xs = ? ++ break n (? xs)
| ? = brk n (? xs) (acc ++ ?)
I’m not sure how to approach this or how the acc helps with this problem. The only idea I have is that the first line should be
break _ [] = []
If anyone can help me get started with this problem, that would be great! Thanks!
accis an abbreviation for “accumulator”—you use it to accumulate your results as you recurse. Look at the types ofbreakandbrkfor some clues:Or more concretely:
Here are some questions to help you figure out how to implement
brk:What should the initial set of results be?
What should you get when you split an empty list?
What should you do when the splitting character appears at the start of the string?
What should you do otherwise?