Category theory question - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Vincent L

Hi. I'm not a Haskell dev but I use F# but I have a question about monads functor and so on I think it should work the same.
I'd like to "combine" 2 monads, Async (which seems close to IO in Haskell, at least I use it only to load data from and to file) and writer (as a way to log what's happening). I'm wrapping all my computations in an Async<Writer<T>> monad.
I want to build a function with type Writer<FileStream, string> -> Async<Writer<string, string>> out of a function that has a FileStream -> Async<string> signature. Is there a tool in category theory to do that ? Bind only works on the outermost monad, and here I like to "go under" the async

Torsten Schmits

are those custom types? in any case, the most usual paradigm is to use a monad transformer, in this case it would be WriterT, that is aware that there is another monad stacked in it. you then implement bind so that it calls Async.bind, but it heavily depends on your implementation of the latter whether this will work

Torsten Schmits

otherwise you would run the Writer before calling the function, store its state in a variable, then map into the result of the function and restore the state