Is there an idiomatic way to express following code in Haskell?
main :: IO ()
main = loop initState1 initState2 initState3
loop :: State1 -> State2 -> State3 -> IO ()
loop s1 s2 s3 = do
s1' <- runService1 s1
s2' <- runService2 s2
s3' <- runService3 s3
loop s1' s2' s3'
This code is very verbose so I probably doing something weird.
main = fix (zipWithM ($) >=>)
[runService1, runService2, runService3]
[initState1 , initState2 , initState3 ]
Compare fix . (>>=) :: IO a -> IO b
, which is forever
.
Edit: This only works if State1
= State2
= State3
. If not, data-fix
allows:
main = fix (traverse unFix >=>)
[ana runService1 initState1, ana runService2 initState2, ana runService3 initState3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With