Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7666885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:57:03+00:00 2026-05-31T14:57:03+00:00

I have a monad for a computation that may fail and does some logging:

  • 0

I have a monad for a computation that may fail and does some logging:

f1 :: WriterT [String] (Either String) a

I have a function that will not fail but does some logging:

f2 :: Writer [String] b

What’s the best way to update the writer monad in f1 using the log from f2, and capture the output of the f2 computation? At the moment I’m doing this:

f2result <- (\(r,l) -> do {tell l; return r}) (runWriter f2)

I am using lift to update the inner monad with a different computation, so switching around the Writer and Either monads will not solve the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:57:04+00:00Added an answer on May 31, 2026 at 2:57 pm

    If you defined f2, the easiest possible approach may be to refactor f2 so it’s defined thusly:

     f2 :: Monad m => WriterT [String] m b
    

    Which shouldn’t be too hard, since Writer w b is defined as WriterT w Identity b, and the Identity monad doesn’t give you anything.

    Then you’d be able to chain them just by doing f1 >> f2.

    If you can’t redefine f2, you could always define your own with the appropriate signature:

     f2' :: Monad m => WriterT [String] m b
     f2' = WriterT . return $ runWriter f2
    

    And if you’ve a bunch of f2 to wrap, you could always define a function to wrap them for you

     wrap :: Monad m => Writer w b -> WriterT w m b
     wrap = WriterT . return . runWriter
    

    So you can do f1 >> wrap f2a >> wrap f2b >> wrap f2c ...

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering why Scala does not have an IO Monad like Haskell. So, in
I have some code that currently uses a ST monad for evaluation. I like
I have a function that might fail, so the value it returns needs to
I have some code that approximates a solution recusively, what it actually does is
Say I have two type classes defined as follows that are identical in function
I have a function that checks whether a type is a subtype of another
Suppose that in a Haskell program I have some data whose type is something
Consider the next example. I have a monad MyM that is just a StateT
I have occasionally encountered a pattern in code which resembles a monad but does
I have a special need for a kind of reverse Maybe monad that when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.