I have two functions, and I'm confused about how the sequence knows which argument to put into a list, and what actually happens with the Lefts in the Either
getMonStat :: T.Text -> IO (Either CmdError MonStat)
..
getMonStats :: [T.Text] -> IO (Either CmdError [MonStat])
getMonStats ms = do
monStats <- mapM getMonStat ms
pure $ sequence monStats
My questions are:
Why does this work? After the mapM, I have
monStats :: [Either CmdError MonStat]. Running sequence on[m a]turns it intom [a]. Why isn't the initial type[m a b]sinceCmdErroris a type as well? And ifCmdErroris a type to consider, how does ghc know to pickMonStatinstead ofCmdErrorto list-ify? Or with types: why does sequence convert tom a b -> m a [b]instead ofm a b -> m [a] b?Which Left from
[Either CmdError MonStat]would the finalCmdErrorinEither CmdError [MonStat]be? The first? A concated string of all of them? I could test but I'm curious in the why as well.
Thank you for any insights into this