[Haskell-cafe] Cons of -XUndecidableInstances
Scott Lawrence
bytbox at gmail.com
Mon Jun 6 06:26:33 CEST 2011
According to the haskell-prime wiki[1], -XUndecidableInstances removes
checks on the form of instance declaration, and just impose a depth
limit to ensure termination (of compilation, I assume?). The listed
Con is that this removes the clear boundary between legal and illegal
programs, and behaviour may be implementation-dependent as the edge of
that boundary is reached. How can I tell when I'm nearing that
boundary? (And where are the sorts of things GHC does with types
documented? I can't seem to find any good explanation of these
things.)
More specifically, I have
class Model m a | m -> a where ...
class Entropy d where ...
instance (Model m a) => Entropy m where ...
The first line requires MultiParamTypeClasses and
FunctionalDependencies (the two seem to go together) - the third
requires UndecidableInstances (since the type variable 'a' appears on
the left but not the right). Is this likely to cause a problem? My
guess is it shouldn't, since it's equivalent to
class Model m a | m -> a where ...
class Entropy d a where ...
instance (Model m a) => Entropy m a where ...
without bothering to actually use 'a' in Entropy - but one never knows...
(Actually, a third type variable has to be introduced to Entropy to
remove the UndecidableInstances dependency - "Constraint is no smaller
than the instance head". This only increases the illogic in my humble
eyes. These examples seem simple enough for GHC to handle nicely...)
[1] http://hackage.haskell.org/trac/haskell-prime/wiki/UndecidableInstances
--
Scott Lawrence
More information about the Haskell-Cafe
mailing list