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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:35:28+00:00 2026-05-25T16:35:28+00:00

What i want to do is to create a type Set in Haskell to

  • 0

What i want to do is to create a type Set in Haskell to represent a generic(polymorphic) set ex. {1,'x',"aasdf",Phi}

first i want to clear that in my program i want to consider Phi(Empty set) as something that belongs to all sets

here is my code

data Set a b= Phi | Cons a (Set a b)
deriving (Show,Eq,Ord)


isMember Phi _ = True
isMember _ Phi = False
isMember x (Cons a b) = if x==a
               then True
               else isMember x b

im facing a couple of problems:

  1. I want isMember type to be

    isMember :: Eq a => a -> Set a b -> Bool
    

    but according to my code it is

    isMember :: Eq a => Set a b -> Set (Set a b) c -> Bool
    
  2. If i have a set of different times the == operator doesn’t work correctly so i need some help please 😀

  • 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-25T16:35:29+00:00Added an answer on May 25, 2026 at 4:35 pm

    Regarding your type error, the problem looks like the first clause to me:

    isMember Phi _ = True
    

    This is an odd clause to write, because Phi is an entire set, not a set element. Just deleting it should give you a function of the type you expect.

    Observe that your Set type never makes use of its second type argument, so it could be written instead as

    data Set a = Phi | Cons a (Set a)
    

    …and at that point you should just use [a], since it’s isomorphic and has a huge entourage of functions already written for using and abusing them.

    Finally, you ask to be able to put things of different types in. The short answer is that Haskell doesn’t really swing that way. It’s all about knowing exactly what kind of type a thing is at compile time, which isn’t really compatible with what you’re suggesting. There are actually some ways to do this; however, I strongly recommend getting much more familiar with Haskell’s particular brand of type bondage before trying to take the bonds off.

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

Sidebar

Related Questions

Suppose I want to create a set of observers based on type. That is
I want to create a replacement class of the built-in type set that can
I want to create a set of classes that share a lot of common
I want to create a helper method that can take in ANY type of
I want to create radio buttons or other type of controls that will act
Suppose I want to create trees of a certain set depth, that is, the
I want to create a delegate type in C# inside a method for the
I want to do something like this create type Item as object ( id
I want to create a C++ class with the following type: It can be
1) If we want to create an instance of a given type during runtime

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.