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

  • Home
  • SEARCH
  • 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 6717731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:53:12+00:00 2026-05-26T08:53:12+00:00

The following is a polymorphic data type in Haskell, interpreted by Hugs. I am

  • 0

The following is a polymorphic data type in Haskell, interpreted by Hugs. I am trying to create an instance of Show for Equality.

The instance declaration says that if a type “a” is in Show, then Equality a is in Show. It should print the two arguments to the constructor Equals a b in the form “a = b”.

data Equality a = Equals a a 

instance (Show a) => Show (Equality a) where
show (Equals a b) = a ++ " = " ++ b

Yet, typing something into Hugs like “(Equality 9 9)” yields:

ERROR – C stack overflow

So, I tried indenting the “show (Equals a b)…” line with a couple of spaces. I’m not sure what the difference would be, but was just playing around and then got this:

Inferred type is not general enough
*** Expression    : show
*** Expected type : Show (Equality a) => Equality a -> String
*** Inferred type : Show (Equality [Char]) => Equality [Char] -> String

Can anyone explain why these errors are occurring, or suggest a better way of implementing this show instance?

Thank you!

  • 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-26T08:53:13+00:00Added an answer on May 26, 2026 at 8:53 am

    The indenting does matter due to Haskell’s at-times-strange whitespace sensitivity. Without the indent, the compiler cannot tell that the following statement belongs to the where.

    The error that you are getting is because the polymorphic type, having no constraints, does not ensure that a and b can concatenated with the ” = ” string. What if you have Equals 1 1. How would you concatenate that without making the Ints strings first?

    However, if you show a and b first, all works out because show martials the values into something that can be concatenated with a String.

    data Equality a = Equals a a
    
    instance (Show a) => Show (Equality a) where
        show (Equals a b) = (show a) ++ " = " ++ (show b)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a lot of data that I'm trying to seed into a polymorphic
The following works fine, as one would expect in a Curry style polymorphic type
I have the following problem. Am trying to make a polymorphic call and the
Following up from this question: How can I unlock a file that is locked
I am trying to serialize and de-serialize (with Json and ObjectMapper ) an polymorphic
I'm trying to understand how to best implement a polymorphic one-to-many in hibernate. Eg:
I'm trying to create a db structure in which I have many types of
i have table AuditLog with fields including: audited_id | audited_type That results in data
I'm following Real World Haskell, and am going through chapter 2, where the exercise
I have the following models class Track include Mongoid::Document field :artist, type: String field

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.