[Haskell] A puzzle and an annoying feature

Daan Leijen daan at cs.uu.nl
Thu Nov 25 15:20:03 EST 2004

Lennart Augustsson wrote:
> Daan Leijen wrote:
>> A "closed class" directive however is an explicit specification that
>> makes the intention of the designer explicit in the program. Since
>> it would solve the puzzle in a rather elegant and explicit way, I
>> thought that it was interesting to mention.
> Indeed, a closed directive would have been fine.  But it's not really
> necessary, the class is obviously closed because of not being exported.
> But the type checker doesn't use this fact.
> I find it somewhat anomalous that there is one unique way to give types
> to my program, but that the type checker refuses to do it. :)

You are right, I feel like that too: one should expect that the type
checker can figure this out, and perhaps it is even really useful.
On the other hand, suppose you decide later to export the
class, and suddenly your code would no longer type check.
The fact that adding an export defintion would lead to a type
error somewhere else in the code might be rather confusing.
(worse! it might be considered inelegant :-)

Personally, I feel that this problem might be better solved by
making a lot of the implicit assumptions (and semantics) of type
classes more explicit, and bring them under user control. Of course,
I do have not have any idea of how this should be done concretely ;-)

(although type class directives might be a step in the right direction?)

-- Daan

More information about the Haskell mailing list