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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:37:05+00:00 2026-05-14T22:37:05+00:00

Say I have two type classes defined as follows that are identical in function

  • 0

Say I have two type classes defined as follows that are identical in function but different in names:

class Monad m where
    (>>=)  :: m a -> (a -> m b) -> m b
    return :: a -> m a

class PhantomMonad p where
    pbind    :: p a -> (a -> p b) -> p b
    preturn  :: a -> p a

Is there a way to tie these two classes together so something that is an instance of PhantomMonad will automatically be an instance of Monad, or will instances for each class have to be explicitly written? Any insight would be most appreciated, thanks!

  • 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-14T22:37:05+00:00Added an answer on May 14, 2026 at 10:37 pm

    Good answer: No, what you’re hoping to do isn’t really viable. You can write an instance that looks like it does what you want, possibly needing some GHC extensions in the process, but it won’t work the way you you’d like it to.

    Unwise answer: You can probably accomplish what you want using scary type-level metaprogramming, but it may get complicated. This really isn’t recommended unless you absolutely need this to work for some reason.

    Officially instances can’t really depend on other instances, because GHC only looks at the “instance head” when making decisions, and class constraints are in the “context”. To make something like a “type class synonym” here, you’d have to write what looks like an instance of Monad for all possible types, which obviously doesn’t make sense. You’ll be overlapping with other instances of Monad, which has its own problems.

    On top of all that, I don’t think such an instance will satisfy the termination check requirements for instance resolution, so you’d also need the UndecidableInstances extension, which means the ability to write instances that will send GHC’s type checker into an infinite loop.

    If you really want to go down that rabbit hole, browse around on Oleg Kiselyov’s website a bit; he’s sort of the patron saint of type-level metaprogramming in Haskell.

    It’s fun stuff, to be sure, but if you just want to write code and have it work, probably not worth the pain.

    Edit: Okay, in hindsight I’ve overstated the issue here. Something like PhantomMonad works fine as a one-off and should do what you want, given the Overlapping– and UndecidableInstances GHC extensions. The complicated stuff starts up when you want to do anything much more complicated than what’s in the question. My sincere thanks to Norman Ramsey for calling me on it–I really should have known better.

    I still don’t really recommend doing this sort of thing without good reason, but it’s not as bad as I made it sound. Mea culpa.

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

Sidebar

Related Questions

Let's say that I have two classes A and B. class A { private:
Say I have two classes and have a requirement that the primary key property
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
Let's say you have two classes that extend UserControl . Each of the controls
Let's say I have two classes. Each class has one parameter. Parameter of first
Say I have two classes with the same identifier for a parameterized type trait
Let's say I have the following two classes: package example.model; public class Model {
Let's say I have two classes like the following: Class A { public: ..
Lets say I have a two classes like this: public class LocalResources { public
Suppose that I have two classes, first a class without any properties, fields or

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.