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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:07:24+00:00 2026-06-12T12:07:24+00:00

Apparently it’s a bad idea to put a typeclass constraint on a data declaration

  • 0

Apparently it’s a bad idea to put a typeclass constraint on a data declaration [src], [src].

I haven’t personally come across a desire to constrain the types within data types I’ve created, but it’s not obvious to me why the language designers “decided it was a bad idea to allow”. Why is that?

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

    I haven’t personally come across a desire to constrain the types within data types I’ve created, but it’s not obvious to me why the language designers “decided it was a bad idea to allow”. Why is that?

    Because it was misleading and worked completely backwards from what would actually be useful.

    In particular, it didn’t actually constrain the types within the data type in the way you’re probably expecting. What it did do was put a class constraint on the data constructor itself, which meant that you needed to satisfy the instance when constructing a value… but that was all.

    So, for instance, you couldn’t simply define a binary search tree with an Ord constraint and then know that any tree has sortable elements; the lookup and insert functions would still need an Ord constraint themselves. All you’d prevent would be constructing an empty tree that “contains” values of some non-ordered type. As far as pattern matching was concerned, there was no constraint on the contained type at all.

    On the other hand, the people working on Haskell didn’t think that the sensible version (that people tended to assume data type contexts provided) was a bad idea at all! In fact, class constraints on a data type declared with GADT syntax (generalized algebraic data types, enabled in GHC with the GADTs language pragma) do work in the obvious way–you need a constraint to construct the value, and the instance in question also gets stored in the GADT, so that you don’t need a constraint to work with values, and pattern matching on the GADT constructor lets you use the instance it captured.

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

Sidebar

Related Questions

Apparently, using AttachDbFilename and user instance in your connection string is a bad way
Apparently Matlab load loads the data from a .mat file into the variable that
Apparently this Tomcat data source gets registered in JNDI. The crystal reports API will
Apparently adding <link rel=stylesheet ... in the document body is considered a bad practice
Apparently i need two queries to get the data i need. I cant give
Apparently I don't understand something about binding ListBox controls to data. Here is a
Apparently xrange is faster but I have no idea why it's faster (and no
Apparently MapReduce queries are one of the slowest things one can do in MongoDB
Apparently when linking a library build with the Intel Composer 12.1 or against the
Apparently there's a maximum number of arguments for std::thread for the std::thread implementation in

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.