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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:51:53+00:00 2026-06-17T18:51:53+00:00

Is it possible to implement a type class as follows: class SomeClass e where

  • 0

Is it possible to implement a type class as follows:

class SomeClass e where
    isEq :: (SomeClass e') => e -> e' -> Bool

where isEq x y would return true when x and y are both the same instance of this type class?

Context: This is a thinly-veiled attempt at getting run-time type tests. While at first I read that Haskell has type erasure, I’ve also read that with recent extensions to GHC, some run-time information in there.

edit: for those wondering about my usecase… I’ve been using type-level programming to ensure certain properties of some of my ADTs, namely involving resource usage. These resources are represented by distinct types (and resource locks are accordingly implemented at type level).

I’m attempting to write an optimisation procedure that requires identification of resource writing/reading. But since all my resources are represented by distinct singletons, whose only common factor (apart from all values being bottom) is the typeclass which groupes them together.

In a nutshell I want to use the results of my type-level programming at a run-time, value level.

  • 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-17T18:51:54+00:00Added an answer on June 17, 2026 at 6:51 pm

    You can do this, as hinted at by Karolis Juodelė, with Data.Typeable:

    Prelude Data.Typeable> :{
    Prelude Data.Typeable| let isEq :: (Typeable a , Typeable b) => a -> b -> Bool
    Prelude Data.Typeable|     isEq x y = typeOf x == typeOf y
    Prelude Data.Typeable| :}
    Prelude Data.Typeable> isEq True ()
    False
    Prelude Data.Typeable> isEq True False
    True
    

    The question is: Why would you not know at run time what the types are, and then why would you care about whether they are equal – can you elaborate your use case?

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

Sidebar

Related Questions

Possible Duplicate: Can GHC warn if class instance is a loop? Consider a type
I'm trying to implement a class that stores a generic nullable type: public class
Is it possible to implement a class constrained to two unique generic parameters? If
I'm learning Python and i've been trying to implement a Singleton-type class as a
Possible Duplicate: Overriding return type in extended interface - Bad idea? Lets consider the
Is it possible to implement a class template in such a way that one
I am trying to implement parameterized class in Java with enum as a type
Is it possible to have an anonymous type implement an interface? I've got a
I asked similar questions here And here This is a sample Type: public class
Is it possible to implement some kind of timeout (time limit) for fork using

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.