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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:37:52+00:00 2026-05-27T18:37:52+00:00

Let’s say I want to create a complex data structure consisting of multiple mutually

  • 0

Let’s say I want to create a complex data structure consisting of multiple mutually recursive data types, with multiple type variables, and some functions to operate on those types:

data Foo x y z = FooA x | FooB (Bar x y z) | FooC (Foo x y z) | FooD (Baz x y z)
data Bar x y z = BarA y | BarB (Baz x y z) | BarC (Bar x y z) | BarD (Foo x y z)
data Baz x y z = BazA z | BazB (Foo x y z) | BazC (Baz x y z) | BazD (Bar x y z)

f :: Foo x y z -> Bar x y z -> Baz x y z
g :: Bar x y z -> Baz x y z -> Foo x y z

Is there a way I can bundle the x y z types, giving them a single name t, and pluck out the x, y, or z types when I actually need them? I don’t want to proliferate x y z throughout my data and function type declarations since adding an additional parameter could affect a lot of code.

i.e.

data Foo t = FooA (GetX t) | FooB (Bar t) | FooC (Foo t) | FooD (Baz t)
data Bar t = BarA (GetY t) | BarB (Baz t) | BarC (Bar t) | BarD (Foo t)
data Baz t = BazA (GetZ t) | BazB (Foo t) | BazC (Baz t) | BazD (Bar t)

f :: Foo t -> Bar t -> Baz t
g :: Bar t -> Baz t -> Foo t

I don’t know how to define the GetX, GetY, and GetZ type ‘functions’ to extract the component types from the bundle.

  • 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-27T18:37:53+00:00Added an answer on May 27, 2026 at 6:37 pm

    You can do this with type families, but it’s almost certainly overkill; it’s generally best to design your data types so that they won’t need any additional parameters in the future. Of course, that comes very close to predicting the future, but when in doubt you should probably add a parameter rather than using a concrete type 🙂

    If you have a concrete example I could give more concrete advice, but generally the best thing to do here is just to keep using the parameters, or else figure out a way to abstract out the relation between the three types so that you only need one parameter that fully specifies the others (without making it just be a list of the types in question).

    Still, here’s an example of how to achieve it with type families:

    type family GetX t
    type instance GetX (a,b,c) = a
    
    type family GetY t
    type instance GetY (a,b,c) = b
    
    type family GetZ t
    type instance GetZ (a,b,c) = c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you create a wizard in an HTML form. One button goes back,
Let's say I'm building a data access layer for an application. Typically I have
Let's say I have a drive such as C:\ , and I want to
Let's say I have saved this kind of data (some text '.date(d).' some text)
Let's say there is a graph and some set of functions like: create-node ::
Let's say I have this MySQL table: OK.. see the type field? Type 0
Let's say I have an image called hello.png with dimensions 200x100 . I create
Let's say I dynamically create a timer like this: System.Timers.Timer expirationTimer = new Timer(expiration
Let's say the Activity I want to start is named OccupyThePieShop I was previously
Let's say I have multiple requirements for a password. The first is that the

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.