Opened 3 years ago

Closed 3 years ago

Last modified 21 months ago

#7775 closed feature request (wontfix)

Mark intentionally omitted type class instances

Reported by: Lemming Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.7
Keywords: instance warning Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


In GHCi I get

Prelude> 2+3::Char

    No instance for (Num Char)
      arising from a use of `+'
    Possible fix: add an instance declaration for (Num Char)
    In the expression: 2 + 3 :: Char
    In an equation for `it': it = 2 + 3 :: Char

In many cases users now actually try to implement the instance Num Char, but this is certainly not a good idea. I would like to tell the user whenever an instance is intentionally unimplemented and why it is missing. Like so

{-# NOINSTANCE Num Char where "There is no sound arithmetic on characters." #-}

The syntax after NOINSTANCE should be like in an instance declaration. It shall be treated like a type class instance, e.g. it shall be checked whether the same instance already exists, or whether it is orphan, or whether it is not Haskell 98, and it should require to enable according extensions like MultiParamTypeClasses. If on resolution a non-instance is chosen then the compiler should print the custom warning "There is no sound arithmetic on characters." instead of "probable fix: add instance".

Change History (4)

comment:1 Changed 3 years ago by monoidal

The "possible fix" message was already removed in 7.6 (#7222).

comment:2 Changed 3 years ago by igloo

  • difficulty set to Unknown
  • Resolution set to wontfix
  • Status changed from new to closed

Thanks for the suggestions. However, I think that now that the misleading advice has been removed, it's not worth implementing the pragma, so I'm closing this ticket.

comment:3 Changed 2 years ago by Lemming

  • Version changed from 7.6.2 to 7.7

There is still a difference between intentionally and unintentionally omitted instances. I find it important to document for me and for others why I have omitted an instance. Also without the "possible fix" message people keep asking why an obvious instance is missing. "Why is this parser not Monoid?" - maybe because there are different ways of viewing it as Monoid. "Why is this identifier type not Num?" - maybe because it makes no sense to multiply identifiers. Or even worse, people do not just ask but start writing (conflicting) orphan instances.

comment:4 Changed 21 months ago by Lemming

Maybe it can still become true via #9334.

Note: See TracTickets for help on using tickets.