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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:08:20+00:00 2026-05-24T09:08:20+00:00

I’m writing a small program with IO actions in Haskell here is module StackQuestion

  • 0

I’m writing a small program with IO actions in Haskell
here is

module StackQuestion where

import Data.Map (Map, insert, fromList)

type Name = String
type Value = String

readValue :: Name -> IO String
readValue name = do     putStrLn name
                        value <- getLine
                        return value

addPair :: Name -> Value -> Map Name Value -> Map Name Value
addPair = insert

names = map show [1..5]
values = map (\char -> [char]) ['a'..'d']
initialMap = fromList (zip names values)

As you can see I have some initial map with values, and function which adds a pair to map, functions which reads a value.

How I can get a clear String value from readValue and pass it to another function ?

Or should I change type Value = String to type Value = IO String and use map Map String (IO String) ?

And if I have Map String (IO String) how can i process this map, how I can get any value depening on data in IO containter (maybe some function func :: (a->b) -> IO a -> b)
For instance is there any way to compare IO String with the clear String ?

If I have function func I would have written

map :: Map String (IO String)
...
func (==) (map ! "key")

What is the strategy of working with IO values ?

  • 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-24T09:08:21+00:00Added an answer on May 24, 2026 at 9:08 am

    How I can get a clear String value from readValue and pass it to another function?

    You can’t; you’ll have to manipulate readValue‘s result while in the IO monad.

    {- read value for name and store both in map -}
    readAndStore :: Name -> Map Name Value -> IO (Map Name Value)
    readAndStore name m  =  do value <- readValue name
                               return $ insert name value m
    

    The return function takes the result of the insert and puts it back neatly into the IO monad. This code exemplifies a general pattern for manipulating values with ordinary functions inside IO.

    Or should I change type Value = String to type Value = IO String

    No; consider what that would mean. IO String means a computation with possible side-effects (IO) with String-typed result. You would be mapping names to computations. (That’s possible, but it’s not what you mean.)

    The example I’ve shown above uses IO (Map Name Value) instead; i.e., a computation in the IO monad with Map-typed result.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am writing an app with both english and french support. The app requests
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.