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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:16:10+00:00 2026-05-26T20:16:10+00:00

Here is a simplified version of my Code: data Bookmark = Bookmark { url

  • 0

Here is a simplified version of my Code:

data Bookmark = Bookmark {
   url :: String
 , label :: String
 } deriving (Show)

genBookmark :: String -> String -> IO Bookmark
genBookmark u l = return ( Bookmark { url = u, label = l } )

But the Strings (url, label) are in the data base, so I have to deal with IO String. There must me a very easy solution, but I don’t see it (and an extensive web search didn’t get me anywhere.)

Basically I want to change my code to:

genBookmark :: IO String -> IO String -> IO Bookmark

Here is another version illustrating the problem:

genBookmark2 :: String -> String -> Bookmark
genBookmark2 u = return ( Bookmark { url = u, label = newlabel } )
                   where newlabel = getLine

With the error “Expected type: String, Actual type: IO String”.

====== EDIT =======

Here is the “real code” that had the error (with the solution that I got from the answer):

getSkosConceptRight :: String -> IO SkosConcept
getSkosConceptRight catName = do
                      suConcepts <- getSubConcepts catName
                      concept <- getMainConcept catName 
                      return ( concept { subConcepts = suConcepts })

getSkosConceptWrong :: String -> IO SkosConcept
getSkosConceptWrong catName = return ( concept { subConcepts = suConcepts })
                        where suConcepts = getSubConcepts catName
                              concept = getMainConcept catName 

getMainConcept :: ShortUrl -> IO SkosConcept
getSubConcepts :: ShortUrl -> IO [SkosConcept]
  • 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-26T20:16:11+00:00Added an answer on May 26, 2026 at 8:16 pm

    You’ve left out the part of your code that gets the string from the db. Either way, you need to “unpack” the String from your IO String.

    In general, you should get rid of the IO as early as possible. So you should really try for a type of String -> String -> Bookmark

    Here’s a simple example:

    -- These will represent your 'get from the db' calls
    ioUrl :: IO String
    ioUrl = return "http://..."
    
    ioLabel :: IO String
    ioLabel = return "my label"
    
    genBookmark :: String -> String -> Bookmark
    genBookmark url label = Bookmark { url = url, label = label }
    

    Now, from main which is in IO, we make our “db” calls to get our strings, unpack the values, and send to our genBookmark function.

    main = do
        url <- ioUrl     -- here, we're removing the "http://..." from the IO String
        label <- ioLabel -- same here
        print (genBookmark url label)
    

    The reason why your genBookmark2 is failing, is because you are trying to use getLine, whose type is IO String in a pure function; hence the expected String, got IO String error message. Also, the type mentions two Strings as inputs, but you only take one.

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

Sidebar

Related Questions

Here is a simplified version of the code I use. I need to rewrite
Here is a simplified version of the code I'm working on. main :: IO
Here's a simplified version of my code that compiles: #include <iostream> class pos {
Here's a simplified version of my code: - (IBAction)convert:(id)sender { /* these two lines
Here is very simplified version of code that i have: class PrintJob : IEntity
I have two data structure classes (this is a simplified version of my code)
The examples here show a very simplified version of a VIEW that I am
Here's a simplified version of the code I'm using to perform simple HTTPS requests:
Here's a simplified version of some code I'm working with right now: int Do_A_Thing(void)
Here is the simplified version of my code <?php session_start(); if($_GET['page'] == login) {

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.