Opened 9 years ago

Last modified 23 months ago

#2641 new feature request

Revise the rules for -XExtendedDefaultRules

Reported by: simonpj Owned by:
Priority: lowest Milestone:
Component: Compiler Version: 6.8.3
Keywords: ExtendedDefaultRules Cc: koen@…, lennart@…, ekmett@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #8171 Differential Rev(s):
Wiki Page:

Description (last modified by simonpj)

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 (22)

comment:1 Changed 9 years ago by igloo

Milestone: 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.

comment:2 Changed 9 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

comment:3 Changed 9 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 ().

comment:4 Changed 9 years ago by simonpj

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

Simon

comment:5 Changed 9 years ago by simonpj

Description: modified (diff)

comment:6 Changed 9 years ago by simonpj

The new rules should also take account of #2854.

comment:7 Changed 9 years ago by simonpj

Summary: Make -XExtendedDeafultRules a bit less liberalRevise the rules for -XExtendedDeafultRules

comment:8 Changed 8 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:9 Changed 7 years ago by igloo

Milestone: 6.12.36.14.1
Priority: normallow

comment:10 Changed 7 years ago by igloo

Milestone: 7.0.17.0.2

comment:11 Changed 7 years ago by igloo

Milestone: 7.0.27.2.1

comment:12 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:13 Changed 6 years ago by igloo

Milestone: 7.4.17.6.1
Priority: lowlowest

comment:14 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

comment:15 Changed 4 years ago by ekmett

Cc: ekmett@… added
Type of failure: None/Unknown

comment:16 Changed 4 years ago by ekmett

Summary: Revise the rules for -XExtendedDeafultRulesRevise the rules for -XExtendedDefaultRules

comment:17 Changed 3 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:18 Changed 3 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:19 Changed 3 years ago by thoughtpolice

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:20 Changed 2 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:21 Changed 23 months ago by thomie

Keywords: ExtendedDefaultRules added

See also #8171, where it is proposed to make the rules more liberal.

comment:22 Changed 23 months ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.