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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:56:10+00:00 2026-05-31T08:56:10+00:00

I was reading Learn You a Haskell’s guide on the state monad , but

  • 0

I was reading Learn You a Haskell’s guide on the state monad, but I had trouble understanding it since the stack example couldn’t compile. In the guide, he used the following piece of code:

import Control.Monad.State  

type Stack = [Int]

pop :: State Stack Int  
pop = State $ \(x:xs) -> (x,xs)  

push :: Int -> State Stack ()  
push a = State $ \xs -> ((),a:xs) 

While I understand what it’s supposed to do, it won’t compile. I have no idea why. The error message is:

Stack.hs:6:7: Not in scope: data constructor `State'

Stack.hs:9:10: Not in scope: data constructor `State'

This makes no sense to me, since “State” is, to my knowledge, in fact a data constructor, defined as

newtype State s a = State { runState :: s -> (a,s) }

Is the guide “wrong”, and if so, how do I fix it?

  • 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-31T08:56:11+00:00Added an answer on May 31, 2026 at 8:56 am

    As I mentioned in comments, you ought to use state instead of State.


    The problem is that State is not standalone data type (or rather newtype), but it is the StateT transformer applied to Identity monad. Actually, it’s defined as

    type State s = StateT s Indentity
    

    and because it’s just type synonym, it cannot have State constructor. That’s why Control.Monad.State uses state.

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

Sidebar

Related Questions

I am reading http://cs.union.edu/~striegnk/learn-prolog-now/html/node3.html#subsec.l1.kb1 , but I am having trouble running the following predicate:
I just have started to learn Haskell and combine reading books and tutorials with
I was reading about regular expressions (I'm a regex newbie, but want to learn
I was reading a Haskell tutorial (Learn You a Haskell) in which the author
I'm reading through Learn You a Haskell and reached a spot where I'm trying
i want to learn Expression blend.. ive been reading some blogs.. about it.. but
I'm trying to learn from reading Mozilla documentation for regular expressions, but there's one
I'm attempting to learn VBA by reading through someone's code and understanding what happens
I am a beginner with haskell and am reading the Learn you a haskell
I am learning Haskell and reading the book, Learn You a Haskell for Great

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.