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 6789547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:37:02+00:00 2026-05-26T17:37:02+00:00

I am stuck with following monad problem: Let’s say I have a standard monad

  • 0

I am stuck with following monad problem:

Let’s say I have a standard monad State with state S = (LS, RS). I also have another monad:

newtype StateP a = StateP {runP :: S -> (a, RS)}

I want to perform some computation using StateP then merge state with state in State monad:

merge m :: StateP() -> State()
merge m = do
 s@(l,r) <- get
 put (l, snd (runP m s))

It is not working, but I don’t get why? Is there another way to achieve such functionality?

  • 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-26T17:37:03+00:00Added an answer on May 26, 2026 at 5:37 pm

    You can use monad transformers to model these requirements more explicitly using two monad stacks: one that can only read LS and one that can both read and write LS.

    type ReadOnlyLS a  = ReaderT LS (State RS) a
    type ReadWriteLS a = StateT LS (State RS) a
    

    To run a ReadOnlyLS within ReadWriteLS, we just need to extract LS from the outermost state layer, give it to the reader layer of the inner computation and lift the resulting computation back into the outer monad:

    merge :: ReadOnlyLS a -> ReadWriteLS a
    merge m = get >>= lift . runReaderT m
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck with this following problem. Say, I have a request which has
I'm new to wicket and stuck with the following problem: I have a table
I'm a beginner programmer and I'm stuck with the following problem: If I have
I am little bit stuck with the following problem. I have two models: class
I am new to Symfony2 and stuck at the following problem. I have an
I am new to Grails and currently stuck at the following problem: I have
I'm stuck with the following problem. I have a class with a constructor (a
I'm new to Mootools and I'm stuck on the following problem. I have this
I am stuck with the following problem: I have the two following correct working
I'm stuck with the following scenario and appreciate any help/advice.. Requirement I have number

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.