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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:17:51+00:00 2026-06-15T19:17:51+00:00

I want to build a nondeterministic state monad in Haskell. This will allow me

  • 0

I want to build a nondeterministic state monad in Haskell. This will allow me to generate all the elements in my search space using the built up state to prune bad locations. Suppose I have the following (pseudo-)code:

primitives :: [State Int Element] 
primitives = [... list of primitive stateful elements ...]                                                                                                                      
combine :: Element -> Element -> State Int Element                                                                                                            
expand :: Depth -> [State Int Element]                                                                                                                        
expand 0 = primitives                                                                                                                                         
expand d = do                                                                                                                                                 
  ... do something to the state ...                                                                                                                           
  left <- expand (d-1)                                                                                                                                        
  right <- expand (d-1)                                                                                                                                       
  let out = combine left right                                                                                                                                
  guard ( ... some check on out ... )                                                                                                                         
  return out        

There are several things here that don’t work: the most basic thing that I need to understand is how to do something to state and then pipe it in to each of the expand branches. I’ve tried a bunch of ways with functions of type State Int [ State Int Element] but, ultimately, once I wrap the branches of the list monad in a state wrapper I can’t remove it, right? So is there a way to do this?

Thanks.

  • 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-06-15T19:17:52+00:00Added an answer on June 15, 2026 at 7:17 pm

    A simple State monad is defined as:

    data State s a = State (s -> (a, s))
    

    This represents a self-contained and deterministic stateful computation. Considering [] as a non-determinism monad, you can have [State s a] which represents a non-deterministic set of deterministic computations, or State s [a] which represents a deterministic computation producing a non-deterministic set of values. In neither case is any non-determinism present in the structure of the stateful computation itself.

    To actually combine the state and non-determinism behaviors in the way you seem to want, you need to combine the two in a way that isn’t possible using just State; this is the purpose of monad transformers. The type StateT s [] a is equivalent to:

    data NonDetState s a = NonDetState (s -> [(a, s)])
    

    What this gives you is non-determinism in the state value with only individual choices observable at any one point in the computation.

    What this does not allow is any interaction between branches; state changes made in one branch will never be visible from other branches, which is what is generally desired in a non-deterministic computation.

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

Sidebar

Related Questions

I want to build a form_tag that will allow me to post a new
I want build a custom Google search. I tried this one My Code <div>
I want build a sketch pad app on iPhone, I assume that this type
I want to build a python program that deletes all the photos from my
I want to build a console-like output using JTextPane. Therefore I am using a
I want to build an local iPhone project without source control using jenkins. However
I want to build a gmail style search app for my site with configurable
I want to build an application using Hibernate and MyBatis integrate with Spring. In
I want to build a string label with a changing suffix. This is to
I want build a search service for one particular thing. The data is freely

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.