8

At times, I run into the "feature" that Haskell only matches instance heads, namely,

instance (a ~ NewDataTyp b) => C a

will now match any type whatsoever, i.e. writing another instance declaration of C in your program will is an error, even if it cannot possibly conflict due to the context a ~ NewDataTyp b. At times, it takes a lot of effort to overcome; I've had to restructure hundreds of lines of code to avoid this limitation.

Are there any language extensions, or descendant languages (Curry? Agda?) that are designed with a higher priority for expressiveness? This could possibly sacrifice (a) openness of the typeclass world (b) polynomial time typechecking.

edit -- for those interested in the question, this page might also be of interest: http://www.haskell.org/haskellwiki/Future_of_Haskell

gatoatigrado
  • 16,580
  • 18
  • 81
  • 143
  • 2
    Removing the open world assumption leads to [more problems than you might expect](http://stackoverflow.com/questions/8728596/explicitly-import-instances/8731340#8731340). As far as I know, the only way to recover from that problem is to add full dependent types, and include the `Ord` instance being used in the `Set`'s type. – ehird Jan 26 '12 at 03:08
  • 1
    Haskell type checking is not polynomial, since HM type checking is (doubly) exponential. – augustss Jan 26 '12 at 04:23
  • 2
    I'm not sure if Chameleon had such an extension. It requires the constraint solver to do backtracking, but I don't see any reason it shouldn't work. – augustss Jan 26 '12 at 04:25
  • @augustss, that sounds more like what I was looking for... will tell you when I have time to look – gatoatigrado Jan 26 '12 at 04:47
  • Agda may be more "expressive" in that the definition will be more concise in a case such as this where you would use GADTs. – Art Taylor Jan 26 '12 at 06:55
  • 2
    If you what you want is _default base case plus extensible type based cases_ I'd go with SYB3 (i.e. SYB-with-class). Trying to achieve this with "OverreachingInstances" is an anti-pattern. – stephen tetley Jan 26 '12 at 21:55

1 Answers1

1

For what it's worth, Scala accepts the more-or-less literal translation of what you just wrote. I'm not sure how useful it is.

trait C[T]
case class NewDataType[T]()

implicit def letItBeInjectiveWhyNot[K[_],T]: K[T] =:= K[T]

implicit def cIsh[A,S](implicit ev: A =:= NewDataType[S]): C[A]
implicit def another: C[Int]

implicitly[C[NewDataType[String]]]
implicitly[C[Int]]
Owen
  • 38,836
  • 14
  • 95
  • 125