[Haskell-cafe] newbie question about Functional dependencies conflict between instance declarations:.....
Hello, I largely don't know what I'm doing or even trying to do, it is a voyage into the unknownbutif 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 workand 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 thisI 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 NotAnIntegerso (in a closed world)this would seem to exclude the contradictionbut... 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 declarationsi.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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] newbie question about Functional dependencies conflict between instance declarations:.....
The constraint on an instance never influences which instance is selected. So as far as instance selection goes, 'instance Foo x' and 'instance C x = Foo x' are the same. The constraint is only checked after the instance is selected. Erik On Fri, Jul 5, 2013 at 2:43 PM, Nicholls, Mark nicholls.m...@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] newbie question about Functional dependencies conflict between instance declarations:.....
You're running into the open worldassumption--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.m...@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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] newbie question about Functional dependencies conflict between instance declarations:.....
Ah So it isn't a closed world So how do I stop my instances clashing? The x in instance Foo Bar x is never intended to be Integer. Mark Nicholls | Lead broadcast corporate architect, Programmes Development - Viacom International Media Networks A: 17-29 Hawley Crescent London NW1 8TT | e: nicholls.m...@vimn.commailto:m...@vimn.com T: +44 (0)203 580 2223 [Description: cid:image001.png@01CD488D.9204D030] From: Tikhon Jelvis [mailto:tik...@jelv.is] Sent: 05 July 2013 2:08 PM To: Nicholls, Mark Cc: haskell-cafe Subject: Re: [Haskell-cafe] newbie question about Functional dependencies conflict between instance declarations:. You're running into the open worldassumption--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.m...@vimn.commailto:nicholls.m...@vimn.com wrote: Hello, I largely don't know what I'm doing or even trying to do, it is a voyage into the unknownbutif 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 workand 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 thisI 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 NotAnIntegerso (in a closed world)this would seem to exclude the contradictionbut... 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 declarationsi.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@haskell.orgmailto:Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe 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