[Haskell-cafe] Improving MPTC usability when fundeps aren't
appropriate?
Daniel Peebles
pumpkingod at gmail.com
Wed Aug 5 12:00:06 EDT 2009
Hi all,
I've been playing with multiparameter typeclasses recently and have
written a few "uncallable methods" in the process. For example, in
class Moo a b where
moo :: a -> a
the moo function is effectively impossible to call (no amount of type
annotations can tell the compiler what you intended b to be there).
Some might suggest adding an a -> b functional dependency, but in some
cases that is not appropriate, as there are multiple possible
instances. Another solution would be to artificially force moo to take
a "dummy" b so that the compiler can figure out which instance you
meant. That's what I've been doing in the mean time, but wouldn't it
be simpler and less hackish to add a some form of "instance
annotation", like a type annotation, that would make it possible to
specify what instance you wanted when it's ambiguous? I'm not sure
what syntax might be appropriate here, but it could also be seen as
"opening" a particular instance, so something "open"-like might be
good.
I don't know whether this has already been discussed much, but I was
unable to find anything that seemed relevant (beyond discussing
relationships between parametrized modules and typeclasses) but I
wanted to know if anyone had any opinion on adding such a feature to
(a future revision of) Haskell? I know people are generally reluctant
to add new syntax elements to a language, but considering the lack of
such a feature and the impossibility of writing such a thing in the
language itself, it seems like it'd be useful to add to the language
itself.
Thanks,
Dan
More information about the Haskell-Cafe
mailing list