Ticket #2641 (new feature request)

Opened 5 years ago

Last modified 9 months ago

Revise the rules for -XExtendedDeafultRules

Reported by: simonpj Owned by:
Priority: lowest Milestone: 7.6.2
Component: Compiler Version: 6.8.3
Keywords: Cc: koen@…, lennart@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by simonpj) (diff)

The -XExtendedDefaultRules flag is very liberal about type-class defaults. Perhaps too liberal:

> *Main> quickCheck (\xs -> reverse xs == xs)
> +++ OK, passed 100 tests.

Not good (reverse on lists is not the identity function). I expect a type error! Reason: reverse on list of () is indeed the identity function!

The rules are currently these:

  • All of the classes Ci are single-parameter type classes.
  • At least one of the classes Ci is numeric, or is Show, Eq, or Ord.

Maybe we should tighten up the second rule to say:

  • All of the classes Ci is numeric, or is Show, Eq, or Ord.

Then the Quickcheck example would not bogusly succeed in typechecking, because there's an Arbitrary constraint involved.

This ticket is to record the idea and canvas opinion. Record thoughts below.

See also

Change History

Changed 5 years ago by igloo

  • milestone set to 6.12 branch

A couple of thoughts:

-Wall would warn about the defaulting. Perhaps in GHCi we could have a quieter warning on by default, so instead of either

<interactive>:1:35:
    Warning: Defaulting the following constraint(s) to type `()'
             `Eq a' arising from a use of `==' at <interactive>:1:35-50
             `Test.QuickCheck.Arbitrary a'
               arising from a use of `Test.QuickCheck.quickCheck'
                            at <interactive>:1:0-51
             `Show a'
               arising from a use of `Test.QuickCheck.quickCheck'
                            at <interactive>:1:0-51
    In the expression: reverse xs == xs
    In the first argument of `Test.QuickCheck.quickCheck', namely
        `(\ xs -> reverse xs == xs)'
    In a stmt of a 'do' expression:
        it <- Test.QuickCheck.quickCheck (\ xs -> reverse xs == xs)

or nothing we could get

Warning: Defaulting a type to ()

or

Warning: Defaulting a type to ()  (use -fwarn-whatever-it-is for more detail)

The other thought is getting very ad-hoc, but I think we only want defaulting to () in an IO a type.

Changed 5 years ago by simonpj

  • cc lennart@… added

See also #2853 (only closed because it duplicates this one), which argues to make ExtendedDefaultRules more liberal, not less!

When finally fixing this, it'd be worth dealing with #1877 at the same time.

Simon

Changed 5 years ago by guest

There's no contradiction between #2853 and this bug report. In #2853 I argue that the defaulting rules should be more liberal about what the context can be when defaulting, but with the context still containing a Num. This report complains about a type being defaulted to ().

Changed 5 years ago by simonpj

Would you care to write a careful specification of your proposed new ExtendedDefaultRules rules?

Simon

Changed 5 years ago by simonpj

  • description modified (diff)

Changed 5 years ago by simonpj

The new rules should also take account of #2854.

Changed 5 years ago by simonpj

  • summary changed from Make -XExtendedDeafultRules a bit less liberal to Revise the rules for -XExtendedDeafultRules

Changed 3 years ago by igloo

  • milestone changed from 6.12 branch to 6.12.3

Changed 3 years ago by igloo

  • priority changed from normal to low
  • milestone changed from 6.12.3 to 6.14.1

Changed 3 years ago by igloo

  • milestone changed from 7.0.1 to 7.0.2

Changed 2 years ago by igloo

  • milestone changed from 7.0.2 to 7.2.1

Changed 21 months ago by igloo

  • milestone changed from 7.2.1 to 7.4.1

Changed 17 months ago by igloo

  • priority changed from low to lowest
  • milestone changed from 7.4.1 to 7.6.1

Changed 9 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2
Note: See TracTickets for help on using tickets.