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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:29:59+00:00 2026-05-24T18:29:59+00:00

If I have an ADT with specified typeclass restrictions I still have to specify

  • 0

If I have an ADT with specified typeclass restrictions I still have to specify the same typeclass for each function using this data type. What the reason for this and how can I reduce unnecessary typing?

E.g.:

data Eq a => C a = V a
g :: C a -> Bool
g (V a) = a == a

I got:

test.hs:32:13:
    No instance for (Eq a)
      arising from a use of `=='
    In the expression: a == a
    In an equation for `g': g (V a) = a == a
Failed, modules loaded: none.

While:

g :: Eq a => C a -> Bool

Works fine, but if I have a long chain of functions it becomes a burden to specify a typeclass everytime:

f :: Eq a => C a -> Bool
f a = g a
  • 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-24T18:30:00+00:00Added an answer on May 24, 2026 at 6:30 pm

    Because the Haskell Report says so, basically. It’s generally regarded as somewhat silly. Quoth the GHC User Guide:

    All this behaviour contrasts with Haskell 98’s peculiar treatment of contexts on a data type declaration (Section 4.2.1 of the Haskell 98 Report). In Haskell 98 the definition

    data Eq a => Set' a = MkSet' [a]
    

    gives MkSet’ the same type as MkSet above. But instead of making available an (Eq a) constraint, pattern-matching on MkSet’ requires an (Eq a) constraint! GHC faithfully implements this behaviour, odd though it is. But for GADT-style declarations, GHC’s behaviour is much more useful, as well as much more intuitive.

    Putting contexts on regular data definitions is discouraged and may (will?) be removed from the language at some point. Either put the context only on the function (which is what actually needs it, anyhow), or use GADT-style syntax to get the behavior you expected.

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

Sidebar

Related Questions

I have a program that's using adt / abstract data classes with data structures.
If I have a Haskell ADT such as: data Foo = A Int Double
HI I have this weird issue. I have the latest version of ADT (11)
I am writing this after struggling a lot with updating my ADT. I have
I have a triggered javascript function to hide dds which have the same class
Let's say that I have an adt representing some kind of tree structure: data
I have created my first application for android Hello android. With using Eclipse, ADT
I have recently updated my ADT and it is now ADT_V20. I have also
I seem to have a tricky problem since the latest ADT update to release
I'm busy implementing a Graph ADT in C++. I have templates for the Edges

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.