Hello, I’m very new to Haskell and to functional programming in general. I have a question about writing recursive functions - namely that I find myself writing ‘helper’ functions to pass state around. I do this in imperative languages as well, but I was wondering if Haskell had some sugar or otherwise to mitigate this? As an example, here is some code I’ve written to replicate the ‘stride’ syntax in eg python [start:end:stride]
-- Gentle replication of indexing syntax from imperative languages
getIndex :: [Char] -> Int -> Char
getIndex list 0 = head list
getIndex (x:xs) idx
| idx > (length (x:xs)) = ' '
| otherwise = getIndex xs (idx - 1)
-- The accumulated word, the source word, the index, the stride
getStrideHelper :: String -> String -> Int -> Int -> String
getStrideHelper acc src idx stride
| idx >= length src = acc
| otherwise = getStrideHelper ((getIndex src idx):acc) src (idx + stride) stride
-- The source word, the starting index, the stride
getStride :: String -> Int -> Int -> String
getStride word start_idx stride = reverse (getStrideHelper "" word start_idx stride)
Any and all comments / advice / criticism appreciated!
Thank you!