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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:13:39+00:00 2026-05-26T06:13:39+00:00

How do you define state in Haskell? My first idea was to use algebraic

  • 0

How do you define state in Haskell? My first idea was to use algebraic data types. I’ve also heard about the state monad, but I don’t really know what it is.
As an example, lets use Texas hold’em poker. We have to represent the following states:

  • The two cards you hold in your hands
  • The cards on the board
  • The actions of the players before you, which can be:
    • fold
    • check
    • bet x
    • raise x
  • The size of the pot
  • The amount of money to call
  • The amount of money to raise (limited poker)
  • 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-26T06:13:39+00:00Added an answer on May 26, 2026 at 6:13 am

    There are two parts to using state in Haskell. The first one is just modeling and creating Datatypes to represent your things (just like in any other language). For example:

    data Card = NumberCard Int | Jack | Queen | King | Ace
    type Hand = (Card, Card)
    data Player = Player Hand Int --a hand and his purse
    data Action = Fold | Check | Bet Int | Raise Int
    type Deck = [Card]
    type TableState = ([Player], Deck)
    --and functions to manipulate these, of course...
    

    Then there is the part of how you use this state. You don’t need to know monads to start making stuff (and you should only bother with the advanced topics when you have the basics mastered anyway). In particular you don’t really need to use “state”, you just need to receive and return these values in functional style.

    For example, a round would be a function that takes a table state (list of players and the deck), a list of player actions and returns a new table state (after the roud had been played given these actions).

    playRound :: TableState -> [Action] -> TableState
    playRound (players, deck) actions = ...
    

    Of course it is now your responsibility to make sure that the old table state is forgotten after you create a new one. Things like the State monad help with this kind of organizational issue.

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

Sidebar

Related Questions

Possible Duplicate: Why use enum when #define is just as efficient? When programming in
My first steps with Flex (currently using Flex 3) and I want to define
I have the following code implementation of Breadth-First search. trait State{ def successors:Seq[State] def
In UML, does an object's state machine define that object's lifecycle? That is, do
I'm using MVC2 and VS2010 developing a website and need to use Application State
I am new to Flex. Recently, I am learning about 'state' concept in Flex.
In Haskell I can easily define a recursive function which takes a value and
I have a State class that is fully implemented as outlined below. I also
What's the state of the art with regards to getting numpy to use mutliple
I'm trying to implement a State Pattern in C++, but have problems with the

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.