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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:08:41+00:00 2026-06-11T12:08:41+00:00

I have a little ambiguous type variable problem. I love haskell but this is

  • 0

I have a little ambiguous type variable problem. I love haskell but this is really what I still fail to handle.
The problem is very easy and involves printf from Text.Printf. Since the problem is very general I’ll just but in some sample code:

program = do
    d <- addd 4 8
    printf "%d" d

addd x y = return (x+y)

Of course printf is imported. The compiler then gives me an, obvious, ambiguous type variable error between Num and PrintfArg. I just don’t know where to fit in the right type signature.

  • 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-11T12:08:42+00:00Added an answer on June 11, 2026 at 12:08 pm

    There are a few places you could put a type signature. Firstly, addd has most general type of (and the most general type is (almost always) what GHC infers when you leave off the signature):

    addd :: (Monad m, Num a) => a -> a -> m a
    

    You could restrict this to only work on a certain type by giving addd an explicit type signature, so that it isn’t at all polymorphic in the arguments, e.g.:

    addd :: Monad m => Int -> Int -> m Int
    -- or,
    addd :: Monad m => Integer -> Integer -> m Integer
    

    Or, you could inform GHC of the input type when you call addd, e.g.:

    d <- addd 4 (8 :: Integer)
    

    and then the type inference will infer that 4 and d are both Integers.

    Lastly, you can give d a type. Either when you use it (if you use d multiple times, you only need a single annotation), like so:

    printf "%d" (d :: Integer)
    

    Or when you set it (requires the GHC extension ScopedTypeVariables):

    {-# LANGUAGE ScopedTypeVariables #-}
    
    [...]
    add = do
        (d :: Integer) <- addd 4 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey most of my issue has been solved but i have little problem This
I have little experience with CSS so this might be a very simple problem.
I have little question. I found this on internet: Type t = typeof(MyClass); MethodInfo[]
I have little experience with silverlight development still but with the potential of silverlight
Apologies if the question appears ambiguous, I have little experience in this area and
I have a question that's not really a problem, but something that made me
I have little problem with specifying my variable. I have a file with normal
I have little unusual problem to solve. I need some hint or links to
I have little bit longer question for you - but hope answer will be
I have little question about how web browser retrieve webpage? I know this User

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.