[GHC] #11692: Suggest default definition of Applicative

#11692: Suggest default definition of Applicative -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: GHCi | Version: 8.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!hs ghci> data A a = A a deriving (Show, Functor) ghci> instance Monad A <interactive>:3:10: error: • No instance for (Applicative A) arising from the superclasses of an instance declaration • In the instance declaration for ‘Monad A’ }}} could suggest defining it in terms of `Monad`: {{{#!hs <interactive>:3:10: error: • No instance for (Applicative A) arising from the superclasses of an instance declaration • In the instance declaration for ‘Monad A’ • Default implementation given a `Monad` instance: instance Applicative A where pure = return (<*>) = Control.Monad.ap }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11692 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11692: Suggest default definition of Applicative -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by hvr): Your suggested warning enhancement is in contradiction to the recommendation expressed in several places (migration guide, AMP wiki page etc, `-Wnoncanonical-monad-instances`) to define `return` in terms of `pure` rather than the other way round. In fact, since GHC 7.10/base-4.8 you don't even need to define `Monad(return)` at all anymore, as it's got a default implementation `return = pure`. Suggesting to define `pure = return` risks ending up with circular definition of `return`/`pure` when refactoring. In fact, together with the MonadFail proposal the proper (minimal, i.e. excluding non-mandatory methods) mental model of the F-A-M-MF hierarchy to have is more or less: {{{#!hs class Functor f where fmap :: (a -> b) -> f a -> f b class Functor f => Applicative f where pure :: a -> f a (<*>) :: f (a -> b) -> f a -> f b class Applicative m => Monad m where (>>=) :: m a -> (a -> m b) -> m b class Monad m => MonadFail m fail :: String -> m a }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11692#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11692: Suggest default definition of Applicative -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 8.1 Resolution: wontfix | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => closed * resolution: => wontfix Comment: Replying to [comment:1 hvr]:
Your suggested warning enhancement is in contradiction to the recommendation expressed in several places (migration guide, AMP wiki page etc, `-Wnoncanonical-monad-instances`) to define `return` in terms of `pure` rather than the other way round.
Wontfix it is. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11692#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC