Overlapping and incoherent instances

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
42 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: Overlapping and incoherent instances

Iavor Diatchki
Hello,

this is clearly a bug in GHC:  where `B` and `C` are imported, there should have been an error, saying that there is a duplicate instance of `Foo Int`.  If there is no ticket for this already, could you please add one?

-Iavor






On Mon, Aug 11, 2014 at 12:35 PM, Dan Doel <[hidden email]> wrote:
On Mon, Aug 11, 2014 at 11:36 AM, Twan van Laarhoven <[hidden email]> wrote:
To me, perhaps naively, IncoherentInstances is way more scary than OverlappingInstances.

​It might be a bit naive. Most things that incoherent instances would allow are allowed with overlapping instances so long as you partition your code into two modules. So unless such a partitioning is impossible, overlapping instances are almost as scary as incoherent instances (unless the module separation somehow makes it less scary).

And actually, with the way GHC handles instances, you can get more incoherent behavior than incoherent instances allow without enabling any extensions, just using modules:

    module A where
      class Foo a where foo :: a

    module B where
      import A
      instance F​
​oo Int where foo = 5
      bar :: Int ; bar = foo

    module C where
      import A
      instance Foo Int where foo = 6
      baz :: Int ; baz = foo

    module D where
      import B
      import C

      quux = bar + baz -- 11​


--
​ Dan​


_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries



_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Overlapping and incoherent instances

Richard Eisenberg-2

But it's really not clear what the solution is!

Richard

On Aug 11, 2014, at 9:27 PM, Iavor Diatchki <[hidden email]> wrote:

Hello,

this is clearly a bug in GHC:  where `B` and `C` are imported, there should have been an error, saying that there is a duplicate instance of `Foo Int`.  If there is no ticket for this already, could you please add one?

-Iavor






On Mon, Aug 11, 2014 at 12:35 PM, Dan Doel <[hidden email]> wrote:
On Mon, Aug 11, 2014 at 11:36 AM, Twan van Laarhoven <[hidden email]> wrote:
To me, perhaps naively, IncoherentInstances is way more scary than OverlappingInstances.

​It might be a bit naive. Most things that incoherent instances would allow are allowed with overlapping instances so long as you partition your code into two modules. So unless such a partitioning is impossible, overlapping instances are almost as scary as incoherent instances (unless the module separation somehow makes it less scary).

And actually, with the way GHC handles instances, you can get more incoherent behavior than incoherent instances allow without enabling any extensions, just using modules:

    module A where
      class Foo a where foo :: a

    module B where
      import A
      instance F​
​oo Int where foo = 5
      bar :: Int ; bar = foo

    module C where
      import A
      instance Foo Int where foo = 6
      baz :: Int ; baz = foo

    module D where
      import B
      import C

      quux = bar + baz -- 11​


--
​ Dan​


_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
123