From 324dd4296e4b515713a64f6b911fe305f2eef754 Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Thu, 6 Jun 2024 21:35:48 +0200 Subject: [PATCH] Add GHC-22705 - NonCanonicalMonad --- message-index/messages/GHC-22705/index.md | 13 +++++++++++++ .../messages/GHC-22705/return/after/Return.hs | 13 +++++++++++++ .../messages/GHC-22705/return/before/Return.hs | 14 ++++++++++++++ message-index/messages/GHC-22705/return/index.md | 7 +++++++ .../GHC-22705/shortfish/after/Shortfish.hs | 13 +++++++++++++ .../GHC-22705/shortfish/before/Shortfish.hs | 14 ++++++++++++++ .../messages/GHC-22705/shortfish/index.md | 7 +++++++ 7 files changed, 81 insertions(+) create mode 100644 message-index/messages/GHC-22705/index.md create mode 100644 message-index/messages/GHC-22705/return/after/Return.hs create mode 100644 message-index/messages/GHC-22705/return/before/Return.hs create mode 100644 message-index/messages/GHC-22705/return/index.md create mode 100644 message-index/messages/GHC-22705/shortfish/after/Shortfish.hs create mode 100644 message-index/messages/GHC-22705/shortfish/before/Shortfish.hs create mode 100644 message-index/messages/GHC-22705/shortfish/index.md diff --git a/message-index/messages/GHC-22705/index.md b/message-index/messages/GHC-22705/index.md new file mode 100644 index 00000000..183cf0c9 --- /dev/null +++ b/message-index/messages/GHC-22705/index.md @@ -0,0 +1,13 @@ +--- +title: Noncanonical ‘return’ definition detected +summary: "'return', or '>>' not defined in terms of 'pure' or '*>'." +severity: warning +flag: -Wnoncanonical-monad-instances +introduced: 9.6.1 +--- + +Since Applicative became a superclass of Monad, the 'return', and '>>' functions of law-abiding +Monad instances are assumed to be identical to the 'pure' and '*>' functions. + +This warning is caused by a definition of 'return' that isn't equal to 'pure', or a definition of +'(>>)' that isn't equal to '(*>)'. diff --git a/message-index/messages/GHC-22705/return/after/Return.hs b/message-index/messages/GHC-22705/return/after/Return.hs new file mode 100644 index 00000000..0cd13815 --- /dev/null +++ b/message-index/messages/GHC-22705/return/after/Return.hs @@ -0,0 +1,13 @@ +module Return where + +data P a = P + +instance Functor P where + fmap _ _ = P + +instance Applicative P where + pure _ = P + _ <*> _ = P + +instance Monad P where + _ >>= _ = P diff --git a/message-index/messages/GHC-22705/return/before/Return.hs b/message-index/messages/GHC-22705/return/before/Return.hs new file mode 100644 index 00000000..98f9e668 --- /dev/null +++ b/message-index/messages/GHC-22705/return/before/Return.hs @@ -0,0 +1,14 @@ +module Return where + +data P a = P + +instance Functor P where + fmap _ _ = P + +instance Applicative P where + pure _ = P + _ <*> _ = P + +instance Monad P where + _ >>= _ = P + return _ = P diff --git a/message-index/messages/GHC-22705/return/index.md b/message-index/messages/GHC-22705/return/index.md new file mode 100644 index 00000000..85e43ad8 --- /dev/null +++ b/message-index/messages/GHC-22705/return/index.md @@ -0,0 +1,7 @@ +--- +title: Non-canonical 'return' defined +--- + +In this example, 'return' is defined in terms of 'P', which doesn't directly use Applicative's 'pure'. + +To fix this, you can define 'return' as 'pure', or leave the definition empty, to use the default value. diff --git a/message-index/messages/GHC-22705/shortfish/after/Shortfish.hs b/message-index/messages/GHC-22705/shortfish/after/Shortfish.hs new file mode 100644 index 00000000..19c069b0 --- /dev/null +++ b/message-index/messages/GHC-22705/shortfish/after/Shortfish.hs @@ -0,0 +1,13 @@ +module Shortfish where + +data P a = P + +instance Functor P where + fmap _ _ = P + +instance Applicative P where + pure _ = P + _ <*> _ = P + +instance Monad P where + _ >>= _ = P diff --git a/message-index/messages/GHC-22705/shortfish/before/Shortfish.hs b/message-index/messages/GHC-22705/shortfish/before/Shortfish.hs new file mode 100644 index 00000000..49b3cfda --- /dev/null +++ b/message-index/messages/GHC-22705/shortfish/before/Shortfish.hs @@ -0,0 +1,14 @@ +module Shortfish where + +data P a = P + +instance Functor P where + fmap _ _ = P + +instance Applicative P where + pure _ = P + _ <*> _ = P + +instance Monad P where + _ >>= _ = P + _ >> _ = P diff --git a/message-index/messages/GHC-22705/shortfish/index.md b/message-index/messages/GHC-22705/shortfish/index.md new file mode 100644 index 00000000..8c74e3a0 --- /dev/null +++ b/message-index/messages/GHC-22705/shortfish/index.md @@ -0,0 +1,7 @@ +--- +title: Non-canonical '>>' defined +--- + +In this example, '>>' is defined in terms of 'P', which doesn't directly use Applicative's '*>'. + +To fix this, you can define '>>' as '*>', or leave the definition empty, to use the default value.