G'day all. On Wed, Jun 25, 2003 at 08:48:12AM -0700, Hal Daume wrote:
I'm not sure this is really necessary (at least syntax-wise).
Well, of course, no extension is absolutely necessary in a Turing-hard language. :-) For the record, here are a couple of other solutions which avoid the problem. You could, for example, make the return type a phantom type: newtype T a = T Int class Trait a where { trait :: T a } instance Trait Int where { trait = T 0 } instance Trait Char where { trait = T 1 } Or construct the type dictionary explicitly: data Traits a = Traits { trait1 :: a, trait2 :: Int } class Trait a where traits :: Traits a instance Trait Char where traits = Traits { trait1 = 'a', trait2 = 16 } Neither solution seems as nice, though, particularly as the traits typeclass idiom is already entrenched (e.g. Bounded).
As far as I can tell with the various --ddump-* flags, the compiler hasn't yet figured out that the argument to trait is useless (i.e., it keeps it in there).
Nor can it, because you could easily declare an instance in another module for which the argument is _not_ useless. This is impossible to detect at compile time.
Of course, the powers that be can weight in on this, and I'm sure that you're aware of the phantom type solution, but I figured I'd post anyway so that others can get a look at types like this for their own benefit...
Sure. Any input is good. I'm not convinced that my proposed solution is the best one. (I'm pretty sure that it's the minimal extension required, though.) Cheers, Andrew Bromage