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

  • Home
  • SEARCH
  • 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 8228991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:38:47+00:00 2026-06-07T16:38:47+00:00

I have the following function: get :: Chars -> IO Chars get cs =

  • 0

I have the following function:

get :: Chars -> IO Chars
get cs = do
    char <- getChar
    let (dats, idx) = (curData cs, curIndex cs)
    let (x,y:xs) = splitAt idx dats
    let replacement = x ++ (ord char) : xs
    return $ Chars replacement idx

and I’d like to get a Chars value out of it, not an IO action. I have no idea how to do this, or if it is even possible.

The Chars type is basically just a container:

data Chars = Chars {
               curData  :: [Int],
               curIndex :: Int
               -- etc.
             }

The specifics aren’t that important, I just want to know if there’s a way for this function to return a Chars instead of an IO Chars.

If not, how do I pass this as an argument to a function that takes a Chars? I’m kind of new to Haskell I/O, but I don’t think I want all of my functions that take Chars as arguments to instead have to take IO Chars as arguments, and then extract and repackage them. It seems unnecessary.

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-07T16:38:48+00:00Added an answer on June 7, 2026 at 4:38 pm

    You can’t, because that would violate referential transparency.

    IO in Haskell is made this way exactly to distinguish between actions whose result and effects may vary depending on the interaction with the environment/user and pure functions whose results are not going to change when you call them with the same input parameters.

    In order to pass the result to a pure function taking a Chars in input you have to call your IO action into another IO action, bind the result with the <- operator to a variable and pass it to your pure function. Pseudocode example:

    myPureFunction :: Chars -> ...
    
    otherAction :: Chars -> IO ()
    otherAction cs = do
      myChars <- get cs
      let pureResult = myPureFunction myChars
      ...
    

    If you’re new to IO in haskell, you may wish to have a look at the Input and Output chapters in Learn You a Haskell for a Great Good! and Real World Haskell.

    There is actually a way to simply get a pure value out of an IO action, but in your case you shouldn’t do it, as you’re interacting with the environment: the unsafe way is ok only when you can guarantee you’re not violating referential transparency.

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

Sidebar

Related Questions

I have the following code in html, I cannot get the Function call back
If I have following in jQuery $(#someId).add(#someOtherId).bind(click, function(e) {... I get the click bound
I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
I have the following code: Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get
For example suppose I have the following app.get('/', function(req, res) { var ip; if(req.headers['x-forwarded-for']){
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I have the following function header in a native DLL: unsigned char* Version_String() I'm
I have a function declared like so: unsigned char** Classifier::classify(){ //... unsigned char **chars
I have the following the functions: This function will get every IP Addresses from
I have the following code function generate_pdf() { $fdf_data_strings = $this->get_hash_for_pdf(); #$fdf_data_names = array('49a'

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.