diff --git a/message-index/messages/GHC-72771/example/after/Lib.hs b/message-index/messages/GHC-72771/example/after/Lib.hs new file mode 100644 index 00000000..32565e41 --- /dev/null +++ b/message-index/messages/GHC-72771/example/after/Lib.hs @@ -0,0 +1,11 @@ +{-# LANGUAGE DefaultSignatures #-} +{-# LANGUAGE TypeOperators #-} + +module Lib where + +import GHC.Generics + +class Enumerate a where + enumerate :: [a] + default enumerate :: (Int ~ a) => [a] + enumerate = [1 ..] diff --git a/message-index/messages/GHC-72771/example/before/Lib.hs b/message-index/messages/GHC-72771/example/before/Lib.hs new file mode 100644 index 00000000..c3f8f4ff --- /dev/null +++ b/message-index/messages/GHC-72771/example/before/Lib.hs @@ -0,0 +1,11 @@ +{-# LANGUAGE DefaultSignatures #-} +{-# LANGUAGE TypeOperators #-} + +module Lib where + +import GHC.Generics + +class Enumerate a where + enumerate :: [a] + default enumerate :: (Int ~ a) => a + enumerate = [1 ..] diff --git a/message-index/messages/GHC-72771/example/index.md b/message-index/messages/GHC-72771/example/index.md new file mode 100644 index 00000000..db277a71 --- /dev/null +++ b/message-index/messages/GHC-72771/example/index.md @@ -0,0 +1,25 @@ +--- +title: Default type signature does not match +--- + +## Error Message +``` +Lib.hs:10:11: error: [GHC-72771] + • The default type signature for enumerate: (Int ~ a) => a + does not match its corresponding non-default type signature + • When checking the class method: + enumerate :: forall a. Enumerate a => [a] + In the class declaration for ‘Enumerate’ + | +10 | default enumerate :: (Int ~ a) => a + | ^^^^^^^^^ +``` + +## Explanation + +Here, we have defined an `Enumerate` typeclass over some type `a`, its instance `enumerate` simply has the signature `[a]`. +At the same time, we define a default method for `enumerate`, which is applied in case the `a` is of type `Int`. +But, this default method has the type signature `a`, which is not equivalent to `[a]`, therefore this error is thrown. + +To resolve this error, we need to define the default method signature to match the method signature. +Therefore, we define the default method signature to produce `[a]` instead of `a`. diff --git a/message-index/messages/GHC-72771/index.md b/message-index/messages/GHC-72771/index.md new file mode 100644 index 00000000..79b2424f --- /dev/null +++ b/message-index/messages/GHC-72771/index.md @@ -0,0 +1,8 @@ +--- +title: Mismatched default method signature +summary: The provided default method implementation's type signature does not match the corresponding method type signature. +severity: error +introduced: 9.8.1 +--- + +This error means that there is a type class with some method `m` for which a [default signature](https://downloads.haskell.org/ghc/9.12.1/docs/users_guide/exts/default_signatures.html) was defined, but that default signature does not match the type signature of `m`.