Extended default rules now specialize Foldable, Traversable to [] (#10971)
ClosedPublic

Authored by KaneTW on Oct 15 2015, 10:55 PM.

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
KaneTW updated this revision to Diff 4506.Oct 15 2015, 10:55 PM
KaneTW retitled this revision from to Extended default rules now specialize Foldable, Traversable to [] (#10971).
KaneTW updated this object.
KaneTW edited the test plan for this revision. (Show Details)
KaneTW added a reviewer: goldfire.
simonpj accepted this revision.Oct 16 2015, 4:31 AM
simonpj added a reviewer: simonpj.
simonpj added a subscriber: simonpj.

Good. But you need a comment in TcSimplify.try_group. With mb_subst we see

-- Make sure the kinds match too; hence this call to tcMatchTy
-- E.g. suppose the only constraint was (Typeable k (a::k))

It's very useful that kind-check is there, because we *also* want to reject the ill-kinded attempt (Eq []). Worth saying so!

compiler/typecheck/TcValidity.hs
352

Better "The types in a 'default' decl can have varying kinds; see Note [Extended defaults]" in TcEnv"

This revision is now accepted and ready to land.Oct 16 2015, 4:31 AM
goldfire edited edge metadata.Oct 16 2015, 8:56 AM

See my design comment here.

Also, this implementation would seem to accept default Either, which is utterly meaningless, as Either has a non-defaultable kind. This is also utterly harmless, but it makes me suspicious of the design.

KaneTW updated this revision to Diff 4527.Oct 16 2015, 11:15 PM
KaneTW edited edge metadata.

Expand implementation comments a little.

KaneTW edited edge metadata.Oct 17 2015, 1:24 PM
KaneTW updated the Trac tickets for this revision.

T10971a and T10971b are already passing, even without compiling this patch. Is that to be expected?

KaneTW marked an inline comment as done.EditedOct 20 2015, 11:11 AM

Oh, thanks. T10971b should pass, that's just intended so I don't mess something up. However, T10971a should fail; the main I put in by accident is preventing that. I'll remove it in a bit.

KaneTW updated this revision to Diff 4577.Oct 20 2015, 12:20 PM

Fix T10971a test.

thomie accepted this revision.Oct 20 2015, 1:49 PM
thomie added a reviewer: thomie.

Also, this implementation would seem to accept default Either, which is utterly meaningless, as Either has a non-defaultable kind. This is also utterly harmless, but it makes me suspicious of the design.

But @goldfire later mentioned in Trac #10971:

I think KaneTW's argument in comment:4 is convincing. I stand down.

So this is ready to go in.

Also note that once we decide on how to handle Trac #10990, doing default (Either) will either throw an error along the lines of "Either not an instance of one of [Num, Foldable, ...]" or have a well specified use-case (displaying specializations in GHCi).

goldfire accepted this revision.Oct 20 2015, 2:51 PM
goldfire edited edge metadata.

Yes, I've been convinced away from my position. Ship it!

This revision was automatically updated to reflect the committed changes.