I have two typeclasses, Foo and Bar, with some instances, defined as such: module Test where class Foo a where foo :: a -> String class Bar a where bar :: a -> String instance Foo Int where foo = show instance Bar Int where bar a = (show a) ++ " bar!" instance Foo Char where foo = show instance Foo a => Bar a where bar = foo If I try to compile this via GHC it complains loudly unless I feed it "-fglasgow-exts -fallow-undecidable-instances -fallow-overlapping-instances", in which case it seems to do the right thing. However, the warnings (and the names of the flags - "undecidable instances" doesn't sound good) make me nervous, and confused. Why is there a problem with saying "every instance of Foo is also an instance of Bar, and here's how"? Abe
Hi,
thing. However, the warnings (and the names of the flags - "undecidable instances" doesn't sound good) make me nervous, and confused. Why is there a problem with saying "every instance of Foo is also an instance of Bar, and here's how"?
From what I understand, this is basically only to prevent cyclic instances, i.e.,
instance Bar a => Foo a where ... instance Foo a => Bar a where ... "undecidable" certainly does sound scary, but I asked Simon PJ about this a few weeks ago and to the best of his recollection at the time, this was the only case it made a difference and, so long as you program compiles with undecidable instances, there should be no runtime errors. That is, undecidable is simply a compile-time property and as long as you don't have any cyclic declarations like the above, you're fine. - Hal
participants (2)
-
Abraham Egnor -
Hal Daume III