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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:07:10+00:00 2026-05-25T19:07:10+00:00

Why does this result in a conflict? class Foo a b | b ->

  • 0

Why does this result in a conflict?

class Foo a b | b -> a where
  foo :: a -> b -> Bool

instance Eq a => Foo a a where
  foo = (==)

instance Eq a => Foo a (a -> a) where
  foo x f = f x == x

Note that the code will compile if I remove the functional dependecy.

I was under the impression that functional dependencies should only disallow stuff like the following, when in fact, it compiles!

class Foo a b | b -> a where
  foo :: a -> b -> Bool

instance Eq a => Foo a a where
  foo = (==)

instance Eq a => Foo Bool a where
  foo _ x = x == x

Same b parameter, yet different a parameters. Shouldn’t b -> a disallow this, as this means a is uniquely determined by b?

  • 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-25T19:07:10+00:00Added an answer on May 25, 2026 at 7:07 pm

    Have you tried actually using the second version? I’m guessing that while the instances compile, you’ll start getting ambiguity and overlap errors when you call foo.

    The biggest stumbling block here is that fundeps don’t interact with type variables the way you might expect them to–instance selection doesn’t really look for solutions, it just blindly matches by attempting unification. Specifically, when you write Foo a a, the a is completely arbitrary, and can thus unify with a type like b -> b. When the second parameter has the form b -> b, it therefore matches both instances, but the fundeps say that in one case the first parameter should be b -> b, but in the other that it should be b. Hence the conflict.


    Since this apparently surprises people, here’s what happens if you try to use the second version:

    • bar = foo () () results in:

      Couldn't match type `Bool' with `()'
        When using functional dependencies to combine
          Foo Bool a,
      

      …because the fundep says, via the second instance, that any type as the second parameter uniquely determines Bool as the first. So the first parameter must be Bool.

    • bar = foo True () results in:

      Couldn't match type `()' with `Bool'
        When using functional dependencies to combine
          Foo a a,
      

      …because the fundep says, via the first instance, that any type as the second parameter uniquely determines the same type for the first. So the first parameter must be ().

    • bar = foo () True results in errors due to both instances, since this time they agree that the first parameter should be Bool.

    • bar = foo True True results in:

      Overlapping instances for Foo Bool Bool
        arising from a use of `foo'
      

      …because both instances are satisfied, and therefore overlap.

    Pretty fun, huh?

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

Sidebar

Related Questions

Why does this code result in error? class CommonRuntine { public: struct TProcess; TProcess
Why does this test program result in a java.lang.IllegalMonitorStateException ? public class test {
Why does this code result in a run-time error vector iterator not incrementable? vector<string>
Why does this work: result = (from e in db.CampaignCodes where e.Code.Equals() && e.Domain.Equals(null)
Does this result in undefined behaviour because the order of evaluation will be unspecified?
Why does this: (new[]{1,2,3}).Cast<decimal>(); result in an InvalidCastException: Specified cast is not valid.
Does this code cause a memory leak: int main(){ int * a = new
What does this mean exactly? I'm doing something like this: File.Copy(@\\foo\bar\baz.txt, @c:\test\baz.txt); MSDN doesn't
I was told that the iPhone does not support multitasking and multithreading. This did
So, why does this result in 0 and how do I find the actual

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.