
#10959: MINIMAL pragma and default implementations -------------------------------------+------------------------------------- Reporter: basvandijk | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): {{{ {-# LANGUAGE DefaultSignatures #-} module Min where class C a where meth :: a -> a {-# MINIMAL meth #-} default meth :: Enum a => a -> a meth = succ instance C Int {- Min.hs:11:10: Warning: No explicit implementation for ‘meth’ In the instance declaration for ‘C Int’ -} }}} It's true there is no ''explicit'' implementation, but surely the intention of the MINIMAL pragma was to warn if we end up with the `meth = error "..."` implementation that the compiler would supply if there was no other implementation at all. If we end up using the default implementation `meth = succ` then it should count towards satisfying the MINIMAL pragma. Incidentally, as I just discovered in testing, the MINIMAL pragma is totally useless in this case: if you don't include an implementation for `meth` in an instance for `C`, ghc will try to use the default implementation, and if it doesn't type check (if there is no instance of `Enum`), that's an error; it doesn't fall back on the `meth = error "..."` implementation for a missing method. So there is no way you can ever not have an implementation for `meth`. (That's not how I thought it worked; I thought the default implementation would just be ignored if it doesn't type check. But it is consistent with the documentation. `default meth :: Enum a => a -> a` is a type signature on ''the'' default implementation, not a description of when to provide ''a'' default implementation.) So I guess an even more minimal example would be {{{ module Min where class C a where meth :: a -> a meth = id {-# MINIMAL meth #-} instance C Int {- Min.hs:7:10: Warning: No explicit implementation for ‘meth’ In the instance declaration for ‘C Int’ -} }}} and now I've convinced myself that there is no bug here at all, just wrong use of MINIMAL. A correct use in conjunction with DefaultSignatures would be if you had two methods in a class, each with a default implementation (using DefaultSignatures) in terms of the other. Then the default implementations should not count for satisfying MINIMAL! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10959#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler