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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:30:55+00:00 2026-06-16T19:30:55+00:00

As a learning exercise, I’m trying to implement a heapsort in Haskell. I figured

  • 0

As a learning exercise, I’m trying to implement a heapsort in Haskell. I figured the State monad would be the right choice to do this, since heaps rely pretty heavily on moving data around inside a single structure (and do notation would be useful). Besides, I’m looking to cement my understanding of monads in general.

The examples on the State monad in Learn You A Haskell (and a number of other tutorials), say that State is defined as:

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

I should be passing a function of type s -> (a,s) (which may or may not be curried in other arguments) to the State value constructor. So my functions look like this:

pop :: Ord a => State (Heap a) a
pop = State pop'
pop' :: Ord a => Heap a -> (a, Heap a)
-- implementation of pop' goes here

push :: Ord a => a -> State (Heap a) ()
push item = State $ push' item
push' :: Ord a => a -> Heap a -> ((), Heap a)
-- implementation of push' goes here

This doesn’t compile, with the following error:

Not in scope: data constructor `State'
Perhaps you meant `StateT' (imported from Control.Monad.State)

From reading the API docs for Control.Monad.State, it looks as though the State value constructor has been removed from the module since these tutorials were written. As a beginner, I find the documentation to be far from self-explanatory. So my question is:

  1. Am I right in believing that the State value constructor is gone?
  2. What should I be using instead?
  • 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-16T19:30:56+00:00Added an answer on June 16, 2026 at 7:30 pm
    1. Yes, it’s gone, replaced by StateT. (The State monad is now defined in terms of the StateT monad transformer.)
    2. You should be using the state function instead.

    I would question whether your approach is correct, however. Instead of worrying about how State is implemented, consider using do-notation and the get and put functions.

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

Sidebar

Related Questions

I'm new to OCaml and attempting to implement List.append as a learning exercise. This
As a learning exercise, I'm trying to implement a class which will emulate the
As a learning exercise, I'm trying to convert an existing Sinatra app to a
I'm trying (as a self-learning exercise) to create a Clojure macro that will generate
This is a learning exercise. I'm attempting to augment memcpy by notifying the user
This is a learning exercise in expression trees. I have this working code: class
Im quite new to generics and as a learning exercise Im trying to create
I'm writing an RSS reader in python as a learning exercise, and I would
As a learning exercise, I'm trying to query ScriptDb and return a person's name
I've been trying to do something as a learning exercise that I thought should

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.