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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:27:20+00:00 2026-06-13T17:27:20+00:00

I’m new to haskell guys. I’m trying to write a gcd executable file. ghc

  • 0

I’m new to haskell guys. I’m trying to write a gcd executable file.

ghc --make gcd

When I compile this code I’m getting the following error.

Couldn't match expected type `IO b0' with actual type `[a0]' 
In a stmt of a 'do' block:
  putStrLn "GCD is: " ++ gcd' num1 num2 ++ "TADA...."
In the expression:
  do { putStrLn "Hello,World. This is coming from Haskell";
       putStrLn "This is the GCD";
       putStrLn "Frist Number";
       input <- getLine;
       .... }
In an equation for `main':
    main
      = do { putStrLn "Hello,World. This is coming from Haskell";
             putStrLn "This is the GCD";
             putStrLn "Frist Number";
             .... }

I don’t understand where my problem is… Here is my code.

gcd' :: (Integral a) => a -> a -> a
gcd' x y = gcd' (abs x) (abs y)
      where gcd' a 0  =  a
        gcd' a b  =  gcd' b (a `rem` b)

main = do
    putStrLn "Hello,World. This is coming from Haskell"
    putStrLn "This is the GCD"
    putStrLn "Frist Number"
    input <- getLine
    let num1 = (read input)
    putStrLn "Second Number"
    input2 <- getLine
    let num2 = read input2
    putStrLn "GCD is: " ++ gcd' num1 num2 ++ "TADA...."

All I know is that read helps me convert my string into an int.

  • 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-13T17:27:22+00:00Added an answer on June 13, 2026 at 5:27 pm

    First, you need parentheses,

    putStrLn ("GCD is: " ++ gcd' num1 num2 ++ "TADA....")
    

    or infix function application ($):

    putStrLn $ "GCD is: " ++ gcd' num1 num2 ++ "TADA...."
    

    Without that, the line is parsed as

    (putStrLn "GCD is: ") ++ gcd' num1 num2 ++ "TADA...."
    

    and the concatenation of the IO-action putStrLn "GCD is: " with a String is what causes the – somewhat cryptic, before one has enough experience – type error.

    From the context in that the line appears – in an IO-do-block – it must have type IO b for some b. But the type inferred from the application of (++) is [a] for some type a. These types cannot be matched, and that’s what the compiler reports.

    Note that after fixing that, you also need to convert the result of gcd' to a String,

    putStrLn $ "GCD is: " ++ show (gcd' num1 num2) ++ "TADA...."
    

    or you’ll see another type error.


    From the comment

    To make my program look nicer. Is there a way that the input area is right next to the statement instead of a line down?

    In general, yes. Instead of using putStrLn which appends a newline to the output string, use putStr which doesn’t.

    putStr "Second Number: "
    input2 <- getLine
    

    In interactive mode (ghci), that works well. stdout is not buffered there. For compiled programmes, stdout is usually line-buffered, that means it will not output anything until a newline shall be output or the buffer is full.

    So for a compiled programme, you need to explicitly flush the output buffer,

    import System.IO -- for hFlush
    
    putStr "Second Number: "
    hFlush stdout
    input2 <- getLine
    

    or turn off buffering altogether

    import System.IO
    
    main = do
        hSetBuffering stdout NoBuffering
        ...
    

    But at least the latter method used to not work on Windows (I’m not sure whether that’s fixed, nor am I absolutely sure that hFlushing works on Windows).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.