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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:45:41+00:00 2026-06-06T09:45:41+00:00

I need to make a Coke Vending Machine in Haskell, but I’m having some

  • 0

I need to make a Coke Vending Machine in Haskell, but I’m having some problems. I don’t understand Haskell very well, so I don’t know what is happening

main = start
       return()

start = do putStr "\nSelect a coin\n1. R$0,25\n2. R$0,50\n3. R$1,00\n"
           coin <- getChar;
           case coin of
                1 -> twentyFive
                2 -> fifty
                3 -> dispensed
                otherwise -> do putStr "Select a valid option"
                                start

twentyFive = do putStr "\nSelect a coin\n1. R$0,25\n2. R$0,50\n3. R$1,00\n"
                coin <- getChar;
                case coin of
                     1 -> fifty
                     2 -> seventyFive
                     3 -> dispensed
                     otherwise -> do putStr "Select a valid option"
                                     twentyFive

fifty = do putStr "\nSelect a coin\n1. R$0,25\n2. R$0,50\n3. R$1,00\n"
           coin <- getChar;
           case coin of
                1 -> seventyFive
                2 -> dispensed
                3 -> dispensed
                otherwise -> do putStr "Select a valid option"
                                fifty

seventyFive = do putStr "\nSelect a coin\n1. R$0,25\n2. R$0,50\n3. R$1,00\n"
                 coin <- getChar;
                 case coin of
                      1 -> dispensed
                      2 -> dispensed
                      3 -> dispensed
                      otherwise -> do putStr "Select a valid option"
                                      seventyFive

dispensed = do putStr "-- Coke Dispensed --"
               return()

But I am getting this error:

Unresolved top-level overloading
*** Binding             : seventyFive
*** Outstanding context : Num Char

What does this mean?

  • 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-06T09:45:48+00:00Added an answer on June 6, 2026 at 9:45 am

    You’ve not indented the body of seventyFive the same way that you’ve indented the bodies of your other functions.

    Should be indented like this instead:

    seventyFive = do putStr "\nSelect a coin\n1. R$0,25\n2. R$0,50\n3. R$1,00\n"
                     coin <- getChar
                     case coin of
                          1 -> dispensed
                          2 -> dispensed
                          3 -> dispensed
                          otherwise -> do putStr "Select a valid option"
                                          seventyFive
    

    The error message is because Hugs thinks the first line of your function is also the last line. (You had the second line not indented as far as that part of the first line that is after the do.)

    Btw, use GHC instead of Hugs if you can (ideally as part of the Haskell Platform) as Hugs has not been maintained for some years.


    Not an error, but it also looks odd that you have

                     coin <- getChar;
    

    Replace with

                     coin <- getChar
    

    More errors:

    main = start
           return()
    

    should be

    main = do start
              return()
    

    or (because we don’t have to have main :: IO (), we can have main :: IO anythingWeWant) just

    main = start
    

    And finally, you are calling getChar, which will give you a Char, but pattern matching as if it gives you a number. You need to enclose the digit in single quotes (e.g. '1' instead of 1).

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

Sidebar

Related Questions

I need to make a cursor in Kinect, but I don't know where to
I am making a multi-table fulltext query.But I met some question. I need make
I need to make some changes to an old Oracle stored procedure on an
I need to make a cURL request to a https URL, but I have
I need make active background which consists of 2 CCSprites which moves successive. But
i need make a special widget for ForeignKeys in Admin, but i need get
I have some part of asynchronous code in my handlers, I need make this
Need to make an multithreading application, which performs some activities and shows progress of
I need to make some markers semi-transparent depending on time. Is there any way
I need make a test of a model, but when I do this: ruby

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.