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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:14:07+00:00 2026-05-23T22:14:07+00:00

I’ve started experimenting with Haskell and have a problem. qqq is a function that

  • 0

I’ve started experimenting with Haskell and have a problem. qqq is a function that should print one string if called with “Nothing” and print other things if called with “Just something”.

The first attempt seems like working:

qqq Nothing = print "There isn't anything to be printed."
qqq (Just x) = print "There is something to be printed." >> print x

main :: IO ()
main = qqq (Just 43)

But:

  • when I try to make main = qqq (Nothing) it fails (“Ambiguous type variable `a0′ in the constraint: (Show a0) arising from a use of ‘qqq'”)
  • When I want to add type signature if fails:
    • qqq :: Maybe x => x -> IO () -> Type constructor 'Maybe' used as a class -> But isn’t it?
    • qqq :: (Maybe x) -> IO (). Now the signature itself looks like succeed. But main = qqq (Just 43) starts failing with that mysterious (Show a0) error like in main = qqq (Nothing) case.

Questions:

  1. Why calling qqq with Nothing is so different than calling with Just 43?
  2. What is (Show a0)? It is mentioned only in error messages. Any attempts to use it lead to something like “Show not in the scope”.
  3. What is correct type signature for this? How to make Haskell print type signature it deduced? Expecting something like:
f 0 = 2
f x = (f (x-1)) + 3

main = print get_type_as_string(f)
-- prints "Number -> Number"
  • 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-23T22:14:08+00:00Added an answer on May 23, 2026 at 10:14 pm

    The type of qqq is:

    qqq :: Show a => Maybe a -> IO ()
    

    That means that qqq takes one parameter of type Maybe a and returns an IO action without a value, with the constraint that a implements the Show typeclass. To find out what Show is, you can use :i Show in ghci.

    Show is a typeclass which requires that a value of the type can be converted to a string. qqq has the constraint because print wants to print out the value (print has type Show a => a -> IO ()). Maybe is not a typeclass but a data type. You can read more about typeclasses here.

    You can let GHC deduce the type signature either by typing the function in a .hs file, then loading the file with ghci (ghci Myfile.hs), and then typing :t qqq for displaying the type. You can also define the function in the interactive session with let qqq n = case n of { Nothing -> print "abc"; Just x -> print "def" >> print x } (it looks a bit different because the function definition has to be on one line in ghci, but the meaning is the same).

    When main calls qqq with qqq (Just 43), it is clear the concrete type of Maybe a is a numeric type (ghci defaults to Integer), so qqq has the concrete type of Maybe Integer -> IO (). However, main calls qqq with qqq Nothing, a could be anything (it is ambiguous) and ghci reports an error.

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

Sidebar

Related Questions

No related questions found

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.