Opened 5 years ago

Closed 5 years ago

#9650 closed bug (invalid)

Unsatisfiable default signature

Reported by: crockeea Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.8.3
Keywords: Cc: dreixel
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC accepts invalid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I discovered the -XDefaultSignatures extension and promptly wrote a default method that I feel should be rejected by the compiler:

{-# LANGUAGE DefaultSignatures #-}

module Foo where

class Foo a where
  foo :: proxy a -> b -> Int
  default foo :: (Integral b) => proxy a -> b -> Int
  foo _ b = fromIntegral b

GHC accepts this code, but rejects the instance instance Foo Bool because No instance for (Integral b) arising from a use of ‘Foo.$gdmfoo’. It seems to me that the class should have never compiled in the first place.

Change History (3)

comment:1 Changed 5 years ago by simonpj

Cc: dreixel added

You point is, I think, that constraints that constrain only b (in this example) cannot possibly be satisfied at the usage site. If you wrote

class Foo a where
  foo :: ...blah..
  default foo :: forall b. (C a b) => ...blah...
  foo = ...

then a suitable instance for C (e.g. instance C Int b) might allow the C a b constraint to be satisfied at the instance declaration.

However, nothing stops you writing

instance Integral b where ...

and now the constraint would be satisfied. You may say this is silly, but people do write instance declarations like this (often OVERLAPPABLE).

So I think the most we could do would be to warn that the default signature looks fishy. And then people would want a way to suppress the warning....

In short, there is merit in what you say, but I don't see an obvious way to take advantage of your observation.

Simon

comment:2 Changed 5 years ago by dreixel

I think there will always be examples of unsatisfiable defaults, and GHC can't, in general, spot them.

comment:3 Changed 5 years ago by crockeea

Resolution: invalid
Status: newclosed

I see Simon's point, so I suppose there's nothing to be done here.

Note: See TracTickets for help on using tickets.