I am trying to figure out how I can recursively define a function while also calling a second function at one of the original integer max values. I don't want to add another integer input however I want to call the second function with the integer from the first function (but only once) I would happily also shorten this down into 1 function if that's better/possible
testFunction::Int->String
testFunction s
|s == 0 = ""
|otherwise = "abc" ++ testFunction (s-1) ++ testFunction2 s
testFunction2::Int->String
testFunction2 s
|s == 0 = ""
|otherwise = testFunction2 (s-1)++"cba"
For example, this will call testFunction recursively and then because it does this it will call testFunction2 multiple times with s-1 in the main function. I only want the content of testFunction2 to be called once and only with the initial value of S without adding any other int inputs. Say I called 'testFunction 2' it currently outputs 'abcabccbacbacba', however I only want cba outputted twice so I really want 'abcabccbacba' Thank you for the help :)
testFunctionto be recursive, but have it call another function recursively.testFunction ... = "abc" ++ helper (s-1) ++ testFunction2 s, wherehelperis the recursive one.f s | s <= 0 = "" | otherwise = "abc" ++ f (s - 1) ++ "cba", sofon increasing values ofswould go:f 0=[],f 1="abc" ++ [] ++ "cba",f 2="abc" ++ ("abc" ++ [] ++ "cba") ++ "cba", and so on. (This is pretty inefficient because it repeatedly appends strings, so in real code I’d usereplicate.)