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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:38:32+00:00 2026-06-08T08:38:32+00:00

I have a type class Shape that declares a number of functions common to

  • 0

I have a type class Shape that declares a number of functions common to all shapes. One of these functions (refine) needs to return a list of subshapes. To express this constraint, I use existential quantification:

data Shapeable = forall a . Shape a => Shapeable a

and have the function return [Shapeable]. I have an additional constraint that some shapes can be refined (via a refine function) while others can check for intersection (via an intersect function). These are mutually exclusive in that a shape that can refine itself cannot check for intersection and vice versa.

If I were not using the quantification, I would have just created two more typeclasses: Intersectable and Refineable. Is there a way to express disjoint function sets within a single typeclass like system?

  • 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-08T08:38:33+00:00Added an answer on June 8, 2026 at 8:38 am

    I believe the closest you can get is by having two existential cases:

    data Shapeable =
        forall a . (Shape a, Intersectable a) => Intersectable a |
        forall a . (Shape a, Refineable a) => Refineable a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, we have a class that one of its fields is of type abstract
I have generic type that looks like: public class GenericClass<T, U> where T :
I have a view model that contains a Product class type and an IEnumerable<
I have a class Shape which should have area defined on all instances. area
Let's say I have an abstract parent class called shape, and that there are
So, please consider the following situation I have a super class of type Shapes
I have two Java class hierarchies that share a common ancestor and implement a
Let's say I have a type: public class Transformer<T, TResult> where T : IMessage
I have a Class with generic type: class Foo<T> { protected boolean validateType(Object obj){
I have simple type Question : public class Question { public string[] Tags {

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.