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

The Archive Base Latest Questions

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

I’m clear about the generic functions and generic data-types. In the generic type: data

  • 0

I’m clear about the generic functions and generic data-types.

In the generic type:

data SB = forall x. (show x) => SB x
instance Show SB where
  show (SB x) = show x

so for any given type x, if it has a signature of Show, and there sure be a show function corresponds to it.

but when typing in ghci, e.g.

:t 1

outputs

1 :: Num a => a

if binds 1 to a name:

let a=1
:t a

now a has a true type.

The question is:

What is 1‘s form in the run-time system(before it has a type, it has only Num), since it can only hold some info of what it can be transformed to.

Are there some internal functions for ‘packing up’ the generic ‘information’ into real things?

For all that I know now, In haskell there should be ‘generic’ tags on some real things, but there should not be some ‘pure generic things’.

Regards!

possible result:

reference to `1` becomes:
get_const_value_1 :: (Num a) => a
get_const_value_1 = fromIntegral (1 :: Integer)
  • 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-22T22:14:50+00:00Added an answer on May 22, 2026 at 10:14 pm

    As Don Stewart said, type classes in GHC are implemented using “dictionaries”. That means that the type class Num is represented as a record of functions (I’m gonna skip the Eq and Show constraints here):

    class Num a where
        fromInteger :: Integer -> a
        ...
    

    becomes

    data Num a = Num { fromInteger :: Integer -> a, ... }
    

    When you define an instance, a new record is created with the functions from the instance:

    instance Num Integer where
        fromInteger = id
        ...
    

    becomes

    numDictForInteger = Num { fromInteger = id, ... }
    

    Now, when you use this function in a polymorphic context, the compiler doesn’t know which dictionary to use, so it generates an extra parameter for it:

    foo :: Num a => a
    foo = 1
    

    becomes

    foo :: Num a -> a
    foo numDict = fromInteger numDict 1
    

    Notice how the constraint Num a => becomes a parameter Num a ->.


    However, when you remove the polymorphism, the compiler knows which dictionary to use statically, so it goes ahead and inlines it instead of generating a parameter:

    foo :: Integer
    foo = 1
    

    becomes

    foo :: Integer
    foo = fromInteger numDictForInteger 1
    

    As a footnote, this is why the monomorphism restriction exists. A polymorphic value would not be a CAF since it requires the dictionary argument. This might cause significantly different performance characteristics from what you might expect and therefore you’re forced to explicitly state that this behavior is what you wanted.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I want to construct a data frame in an Rcpp function, but when I
I have some data like this: 1 2 3 4 5 9 2 6
I used javascript for loading a picture on my website depending on which small
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.