[Haskell-cafe] newbie question about "Functional dependencies conflict between instance declarations:".....

Tikhon Jelvis tikhon at jelv.is
Fri Jul 5 15:07:40 CEST 2013


You're running into the "open world"assumption--anybody could come along
and make Integer part of your NotAnInteger class, and there's nothing you
can do to stop them. This is a design tradeoff for typeclasses: typeclass
instances are always global and are exported to all other modules you use.
This means you cannot ensure a type is *not* part of a typeclass. (Or, at
the very least, you can't convince GHC of this fact.)

For more information about this, take a look at the following StackOverflow
question:
http://stackoverflow.com/questions/8728596/explicitly-import-instances
On Jul 5, 2013 8:47 AM, "Nicholls, Mark" <nicholls.mark at vimn.com> wrote:

>  Hello,****
>
> ** **
>
> I largely don’t know what I’m doing or even trying to do, it is a voyage
> into the unknown….but….if I go…****
>
> ** **
>
> > {-# LANGUAGE MultiParamTypeClasses #-}****
>
> > {-# LANGUAGE FunctionalDependencies #-}****
>
> > {-# LANGUAGE FlexibleInstances #-}****
>
> > {-# LANGUAGE UndecidableInstances #-}****
>
> ** **
>
> > class Foo x y | x -> y, y -> x****
>
> > instance Foo Integer Integer****
>
> ** **
>
> That seems to work….and my head seems to say…your created some sort of
> binary relation between 2 types…and made <Integer,Integer> a member of it…
> ****
>
> ** **
>
> Something like that anyway….****
>
> ** **
>
> Then I go….****
>
> ** **
>
> > data Bar****
>
> ** **
>
> > instance Foo Bar x****
>
> ** **
>
> Error!....but I’m think I understand this….I can’t claim that <Bar,x> is a
> member of Foo and <Integer,Integer> is member of Foo and preserve my
> functional dependencies, because <Bar,Integer> is now a member of Foo..***
> *
>
> ** **
>
> Bad programmer…….****
>
> ** **
>
> ** **
>
> So how I naively go….****
>
> ** **
>
> ** **
>
> > class NotAnInteger a****
>
> ** **
>
> > instance (NotAnInteger x) => Foo Bar x****
>
> ** **
>
> I haven’t declared integer to be “NotAnInteger”….so (in a closed
> world)….this would seem to exclude the contradiction….but…****
>
> ** **
>
> ** **
>
> Functional dependencies conflict between instance declarations:****
>
>       instance Foo Integer Integer -- Defined at liam1.lhs:7:12****
>
>       instance NotAnInteger x => Foo Bar x -- Defined at liam1.lhs:13:12**
> **
>
> ** **
>
> So ****
>
> **i)                    **I clearly don’t understand something about the
> type system.****
>
> **ii)                   **I don’t know how to restrict type variables in
> instance declarations….i.e. how do I use the notion of “Foo” across
> different combinations of types, without them colliding.****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
>
>
> CONFIDENTIALITY NOTICE
>
> This e-mail (and any attached files) is confidential and protected by
> copyright (and other intellectual property rights). If you are not the
> intended recipient please e-mail the sender and then delete the email and
> any attached files immediately. Any further use or dissemination is
> prohibited.
>
> While MTV Networks Europe has taken steps to ensure that this email and
> any attachments are virus free, it is your responsibility to ensure that
> this message and any attachments are virus free and do not affect your
> systems / data.
>
> Communicating by email is not 100% secure and carries risks such as delay,
> data corruption, non-delivery, wrongful interception and unauthorised
> amendment. If you communicate with us by e-mail, you acknowledge and assume
> these risks, and you agree to take appropriate measures to minimise these
> risks when e-mailing us.
>
> MTV Networks International, MTV Networks UK & Ireland, Greenhouse,
> Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions
> International, Be Viacom, Viacom International Media Networks and VIMN and
> Comedy Central are all trading names of MTV Networks Europe.  MTV Networks
> Europe is a partnership between MTV Networks Europe Inc. and Viacom
> Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley
> Crescent, London, NW1 8TT.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130705/e072bb6c/attachment.htm>


More information about the Haskell-Cafe mailing list