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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:04:08+00:00 2026-05-28T20:04:08+00:00

I am developing a function which reads user input of the form a 2

  • 0

I am developing a function which reads user input of the form “a 2” and then converts it into a tuple and adds it to a list of tuples. This is supposed to keep happening until the user types in “done”.

The code is as follows…

getVectorData vector1 =  do
                putStrLn "Enter dimension and coefficient separated by a space: Enter \"Done\" to move on to next vector: "
                appData <- getLine

                if appData == "done" then
                    putStrLn "That's it"
                else do
                    createVectorTuple (words appData) : vector1
                    getVectorData vector1

createVectorTuple :: [String] -> (String, Float)
createVectorTuple vectorData = ((head vectorData) , (read (last vectorData) :: Float))

How ever, when trying to execute this file, I get the error

> ERROR file:.\MainApp.hs:13 - Type error in final generator
*** Term           : getVectorData vector1
*** Type           : IO ()
*** Does not match : [a]

What am I doing wrong?

  • 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-28T20:04:09+00:00Added an answer on May 28, 2026 at 8:04 pm

    You are mixing IO with pure non-IO functions.

    getVectorData vector1 =  do
        putStrLn "Enter dimension and coefficient separated by a space: Enter \"Done\" to move on to next vector: "
        appData <- getLine
    
        if appData == "done" then
            putStrLn "That's it"
    

    The above is all IO

        else do
            createVectorTuple (words appData) : vector1
    

    createVectorTuple is a non-IO function. Since the preceding part is an IO do-block, only expressions of type IO a may appear in that do-block. However, you get the somewhat strange error message because the precedence of function application is highest, so the above line is parsed

    (createVectorTuple (words appData)) : vector1
    

    which is an expression of type [(String, Float)] (if vector1 has that type). Now [] is a monad too, so expressions of type [a] can appear in do-blocks, but then all expressions in that block must have list type. But

            getVectorData vector1
    

    is an expression of type IO () as has been determined from the part above. Thus the types don’t match. Admittedly, the reported type error is not the clearest possible in that situation.

    You probably want something along the lines of

    let vector2 = createVectorTuple (words appData) : vector1
    getVectorData vector2
    

    or something completely different, I can’t tell from the short snippet.

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

Sidebar

Related Questions

I am still developing this function, but here is what I am intending it
I have a dll which includes a function called ReadPort that reads data from
I am currently developing a jquery function which I intend to use to replace
I am developing an application which is based on user challenges. The app also
I am developing an application which reads from the accelerometer (20 samples per second)
I'm developing a function in which I'd like to check which useragent is currently
I am developing an android application. Now i have created one function which create
I am developing a firefox extension which reads and writes to a sqlite database.
I am currently developing a function that is meant to execute dynamically created SQL
I was developing a small function when trying to run an enumerator across a

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.