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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:00:02+00:00 2026-06-09T04:00:02+00:00

When I try to compile this: module Main where import qualified Data.Vector.Unboxed.Mutable as MV

  • 0

When I try to compile this:

module Main where

import qualified Data.Vector.Unboxed.Mutable as MV
import Control.Monad.ST

myRead mv = runST $ MV.read mv 0

I get the following error message:

Could not deduce (t ~ U.MVector s a)
    from the context (U.Unbox a)
      bound by the inferred type of myRead :: U.Unbox a => t -> a
      at src/Main.hs:53:1-32
      `t' is a rigid type variable bound by
          the inferred type of myRead :: U.Unbox a => t -> a
          at src/Main.hs:53:1
    Expected type: U.MVector (PrimState (ST s)) a
      Actual type: t
    In the first argument of `MV.read', namely `mv'
    In the second argument of `($)', namely `MV.read mv 0'
    In the expression: runST $ MV.read mv 0

Can I make a read from a mutable vector pure with runST? If so, how? I assume it entails a type signature for myRead, but everything I’ve tried has just lead to more and more incomprehensible error messages.

EDIT: Highlighting some context I just put in a comment below: The context here is that I have a function that takes in a mutable vector, does some computations using the mutable vector as a temporary scratch space, then needs to return a float value. Because I don’t care about the changes to the mutable vector, I was wondering if there was a way to ignore its “state change” and simply return one of the values from inside 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-06-09T04:00:04+00:00Added an answer on June 9, 2026 at 4:00 am

    The other answers are good, but I think there is one basic thing about ST that you are missing. Each call to runST is effectively making a new “ST universe” in which some imperative code runs. So if you have one call to runST to make the array and a separate call to runST to get a value out of that array, things can’t possibly work. The two runST calls want their own unique universes, whereas you want them to share one.

    What the answers explained in some detail is how these unique universes are created by some type-system trickery.

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

Sidebar

Related Questions

When I try to compile this: import java.awt.* ; class obj { public static
When I try to compile this code: struct BasicVertexProperties { Vect3Df position; }; struct
When I try to compile this: public static Rand searchCount (int[] x) { int
When i try to compile this: public static int compareCardhl (Card c1, Card c2)
When I try to compile this project I get the following error. I would
I'm getting a nothing to repeat error when I try to compile this: search
When I try compile with maven 3.0.4, Eclipse give me this error: Failed to
When I try to compile TOSSIM in tiny OS v-2.0.2 , this is the
I want to try this module https://github.com/creationix/nstore fore simple storage . But when i
I'm trying to compile the following code with GHC: module Test where import Maybe

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.