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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:39:28+00:00 2026-06-17T21:39:28+00:00

I have something similar to this class in my code. It does not make

  • 0

I have something similar to this class in my code. It does not make sense for my situation to add a’ as another parameter to class Foo.

class Foo a where
    type FCtx a a' :: Constraint
    type FCtx a a' = ()

    f :: (FCtx a a') => a -> a'

data D b = D b

instance (Integral b) => Foo (D b) where
    -- the next line does not compile because b' does not appear on the LHS
    type FCtx (D b) a' = (a' ~ D b', Integral b') 

    f (D x) = D $ fromIntegral x

For this specific instance of Foo, I want a' to be related in this way. The only way I’ve come up with to make this work is by adding a “dummy” class with an “obvious” type synonym:

class DClass d where
   type DType d

instance DClass (D b) where
    type DType (D b) = b

The Foo instance now becomes:

instance (Integral b) => Foo (D b) where
    type FCtx (D b) a' = (a' ~ D (DType a'), Integral (DType a'))
    f (D x) = D $ fromIntegral x

The problem is that I had to create an entire class (and instance) for my specific data type just to express the type synonym/functional dependency that (D b) determines b. I will not have any other instances of this class, because I always want DType a' to mean the type parameter to D b.

What I would like to do instead is something like:

type DParam (D b) = b

instance (Integral b) => Foo (D b) where
     type FCtx (D b) a' = (a' ~ D (DParam a'), Integral (DParam a'))
     f (D x) = D $ fromIntegral x

or maybe even some nicer way of expressing this Constraint without using type synonyms at all. It seems silly that I should be forced to create an (open) class with a type synonym with a single instance just to accomplish this, and unsafe that others could potentially create new instances that I did not intend.

At the least, would there not be some canonical way of turning a “pattern matched type synonym” into the class/instance DClass above?

  • 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-17T21:39:29+00:00Added an answer on June 17, 2026 at 9:39 pm

    Slightly lighter weight, using type families:

    type family DParam d :: *
    type instance DParam (D b) = b
    

    Not sure if you can do much better right now…

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

Sidebar

Related Questions

I have something like this in my controller: class houseController = { ... code
I have something very similar to this example: https://developers.google.com/maps/documentation/javascript/examples/directions-simple All I am trying to
I am just trying to find out that does puppet have something similar to
I have an ASP.NET web site with something similar to the following code: .aspx
I have an object with event handlers and I want to make something similar
I have successfully constructed something similar to the following code in visual studio 2008:
If you look at the code for a read-only collection it does not have
I have been working on a multiple inheritance code which looks similar to this:
My current non-compiling code is similar to this: public abstract class A { }
I have something similar to that: <table> <tr> <td>Hello,<br/>World!</td> </tr> </table> Both lines Hello,

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.