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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:43:12+00:00 2026-05-24T10:43:12+00:00

I want to make an entries :: Map(String -> Entry) so I can easily

  • 0

I want to make an entries :: Map(String -> Entry) so I can easily access each entry by name. To this end, I have the code

  Just xml ←  xmlNew "blah.glade"
  ...
  entries ← fromList $ [(name,entry) | name <- entryList 
      , entry <- xmlGetWidget xml castToEntry name]

(where entryList is a list of entry names, e.g. ["name1","name2",...]).

However, the list comprehension comes up with the following error:

   Couldn't match expected type `[t]' against inferred type `IO Entry'
    In the expression: xmlGetWidget xml castToEntry name
    In a stmt of a list comprehension:
        entry <- xmlGetWidget xml castToEntry name
    In the second argument of `($)', namely
        `[(name, entry) |
              name <- entryList, entry <- xmlGetWidget xml castToEntry name]'

I can’t see why it’s expecting a list of anything. Can anyone help with this?

  • 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-24T10:43:13+00:00Added an answer on May 24, 2026 at 10:43 am

    It’s because <- in a list comprehension expects the right hand side to be a list. You’re trying to use it to bind the result of an IO action, but that’s only valid in do notation (without extensions, at least).

    The problem is that xmlGetWidget returns IO Entry, but you want a map of Entry. That means you’ll have to compose those IO actions into a larger one.

    In the end, you’ll want something like this:

    let getEntry name = do entry <- xmlGetWidget xml castToEntry name
                           return (name, entry)
    entries <- fromList <$> mapM getEntry entryList
    

    Here, I’ve created a helper function getEntry :: String -> IO (String, Entry) to get the entry and pair it up with its name.

    Next, I use mapM to map getEntry over the list of names. Note the difference between map and mapM. If I had used map, I would have gotten a list of actions, i.e. [IO (String, Entry)], when what I want is an action returning a list, i.e. IO [(String, Entry)].

    Now, having constructed that IO action, I convert it to a Map using fromList with the operator <$>. Also known as fmap, <$> applies a pure function to the thing inside the IO, so the result is of type IO (Map String Entry).

    Finally, the result of this IO action can be bound to entries.

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

Sidebar

Related Questions

I have style sheet with a class name changebackgroundcolor i want make change in
I want to make sure people can't type the name of a PHP script
I have a JSON file that I want to parse. For each entry in
i want to make some .doc files with some entries in a database. here
In Django's templates system, if I have a block that I want to make
I want to get the newest entries for each of my threads (private messaging
I have an Excel spreadsheet with a few thousand entries in it. I want
I have a read-only mssql- view , and I want to map it to
I want to make something similar to the listbox.children property. I know I can
i want to make a selection that excludes the entries that start with 07,

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.