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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:44:07+00:00 2026-05-26T07:44:07+00:00

when I try something in ghci after loading the file like putStrLn $ showManyP

  • 0

when I try something in ghci after loading the file like putStrLn $ showManyP "%d" 10
it works but why this don’t work when I write it in the file
main = putStrLn $ showManyP "%d" 10

It gives this error

printf.hs:37:19:
Ambiguous type variable `a0' in the constraints:
  (Format a0) arising from a use of `showManyP' at printf.hs:37:19-27
  (Num a0) arising from the literal `10' at printf.hs:37:34-35
Probable fix: add a type signature that fixes these type variable(s)
In the second argument of `($)', namely `showManyP "%d" 10'
In the expression: putStrLn $ showManyP "%d" 10
In an equation for `main': main = putStrLn $ showManyP "%d" 10
Failed, modules loaded: none.

The actual file begins here:

{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
import Data.List (intercalate,isPrefixOf)
class Showable a where
    showManyP :: String -> a

instance Showable String where
    showManyP str = str

instance (Showable s,Format a) => Showable (a->s) where
    showManyP str a = showManyP (format str a)

class Format a where 
    format :: String -> a -> String

instance Format String where
    format str a = replace "%s" str a

instance Format Char where
    format str a = replace "%c" str [a]

instance Num a=>Format a where
    format str a = replace "%d" str (show a)

replace :: String -> String -> String -> String
replace f str value = intercalate value $ split str f

split :: String -> String -> [String] 
split [] f = [[]]
split str [] = [str] 
split str@(x:xs) f | isPrefixOf f str = [[],drop (length f) str]
                   | otherwise = let (y:ys) = split xs f
                                 in [x:y] ++ ys
  • 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-26T07:44:08+00:00Added an answer on May 26, 2026 at 7:44 am

    In ghc, When you enter a numeric constant like 10, it can be any type that is an instance of Num. If there are no additional type constraints, it is an undecided instance, and you must provide a specific type; i.e. (10 :: Int). Ghci is interactive, and it would be a pain to have to add types to numbers, so it helps you out by assuming that, in the absence of additional type constraints, that things that look like integers are of type Integer. This is explained in the GHC User Guide 2.4.5. Type defaulting in GHCi

    According to the “2010 Haskell Report”, in 4.3.4 Ambiguous Types, and Defaults for Overloaded Numeric Operations, there is a default keyword that allows you to take advantage of this behavior in compiled modules.

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

Sidebar

Related Questions

I would try something like this but it isn't allowed. function GetDynamicModulesProperties() { var
I try something like this below, but the complier warns me for this type
Using something like this: try: # Something... except Exception as excep: logger = logging.getLogger(component)
I want to do something like this... try { # Something in this function
For example, I try to do something like this: - (BOOL)compare:(NSDecimal)leftOperand greaterThan:(NSDecimal)rightOperand { BOOL
I'm new to jQuery and I try something like this: <ul id=CatNavi> <li class=CatLevel1
I'm a little confusing when try something like this b = [lambda x:x**i for
I'm pretty proficient in PHP, but want to try something new. I'm also know
Every time I try to do something seemingly-simple in CSS, it doesn't work. I
Currently I'm doing this: try: something = next(iterator) # ... except StopIteration: # ...

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.