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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:34:48+00:00 2026-06-07T20:34:48+00:00

Total newbie here, struggling. I’m trying to define a type class for sets. For

  • 0

Total newbie here, struggling.

I’m trying to define a type class for sets. For this case it would only require the definition of ‘exists’. ‘exists’ would take a set and function on a set item, and return
a boolean. How can I define that in Haskell?

Is the following even in the right direction? So there is the type class definition and an
implementation of set with list, for which ‘exists’ returns true for now..

-- Set.hs --

class Set a b where

  exists :: a -> (b -> Bool) -> Bool


-- ListSet.hs --

instance Set ListSet a where 

  exists a f = True

—

(result: Too many parameters for class `Set’)

  • 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-07T20:34:52+00:00Added an answer on June 7, 2026 at 8:34 pm

    You can do it this way, with enough extensions. At the very least, you’ll need multiple-parameter type classes. However, it will be very annoying to use: you’ll need to specify explicit type signatures all over the place. One way to fix it is to introduce a functional dependency (using another extension):

    class Set a b | a -> b where
        exists :: a -> (b -> Bool) -> Bool
    

    This says that if you know the type of the set, you know the type of the elements, too. However, there’s a simpler way that works without any extensions:

    class Set f where
        exists :: f a -> (a -> Bool) -> Bool
    

    Here, the type class ranges over higher-kinded types, which is a neat trick and hard to come up with on your own if you’ve never seen it before!

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

Sidebar

Related Questions

I am trying to use boost string algorithms for case insensitive search. total newbie
total newbie here. i was trying to replace a character in char * but
Total newbie question here...Today while trying to calculate sum of a list of integers(actually
I know this is a total newbie question, but the answer may not be
Total newbie to XPath and Java here. What I'm attempting to do is something
This is a total newbie question, but I wonder if someone could assist with
I am a total Flash newbie. I just installed Flash CS5 and ran this
A total newbie question, so please bear with me here ;) When a key
Bit of a Rails newbie here so please bear with me. I am trying
tsql newbie here. I have a table, similar to this one: CarId CarName UserId

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.