I have a recursive function that receives a data object with number of fields, something like:
data MyState = {
first :: Int,
second :: String,
third :: Bool,
...
}
type Result = Int
This recursive function changes it during the execution and passes it to itself for the next execution. It looks like following:
-- This is a pseudocode, just to give an idea about the workflow.
process :: MyState -> Result
process st = go st
where go st | first == 1 = (go . changeFunc1) st
| first == 2 = (go . changeFunc2) st
| otherwise = generateResult st
changeFunc1 :: MyState -> MyState
changeFunc1 st | third st == True && second st == "abc" = st {first = inc}
| otherwise = st
where inc = first st + 1
...
In this case, instead of passing MyState parameter between functions I could use State monad and I would need to wrap/unwrap monad all the time. I am relatively new to Haskell and need a recommendation, which approach is better in my case. Thanks.