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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:59:00+00:00 2026-06-11T01:59:00+00:00

I have started this a new question as it became a follow-on from my

  • 0

I have started this a new question as it became a follow-on from my previous question.

If I have two data types which are composed of similar constructors:

data A = X | Y | Z
data B = X | Y

is there no way I can somehow represent this as:

data A = C | Z
data B = C

data C = X | Y

if you can see what I am doing- I am trying to group the X | Y into one data type, which can then be used by multiple other data types. I cannot seem to get the compiler to allow this, or if it does, I cannot pattern-match against the X or Y, only the C??

I get the error message that C has been declared multiple times.

I thought I could maybe use types, but they do not allow multiple typings.

EDIT

Even if I declare the long way (like below), it still won’t compile and says X and Y have multiple declarations:

data A = X | Y | Z
data B = X | Y
  • 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-11T01:59:02+00:00Added an answer on June 11, 2026 at 1:59 am

    Not only can’t you do this, you also can’t do your first option – i.e. you can’t have two types in the same module that both have constructors named X and Y.

    If you could do this, what should the type of X be – C, A or B? The most obvious answer would be C, but then you wouldn’t be able to use it in a context where an A or a B are required (note that Haskell has no subtyping), so that would defeat the purpose of the whole construct.

    The best you can do is to wrap C in a constructor of A and B, i.e.:

    data A = AC C | Z
    data B = BC C
    data C = X | Y
    

    Then you could wrap a C with either the AC or the BC constructor to create a value of type A or B respectively.

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

Sidebar

Related Questions

I have started using Simple-form and Bootstrap and I have tried to follow this
Let me preface this question. I have just started using jquery, so please be
I have this script loaded on a page: (function() { window.alert('bookmarklet started'); function AjaxSuccess(data,
I am extremely new to Java (just started this weekend) and have a background
I recently started this question in another thread (to which Reed Copsey graciously responded)
So, I have started with this: copy | dir /s /b | find myFile
I have started writing a Macro in Visual Studio 2005 like this: Public Sub
I have started learning HTTPUNIT and found one basic example. In this example it
Ever since I started programming this has been something I have been curious about.
I've just started with this section of the tutorial. I only have a basic

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.