Skip to content

Add GHC-22705 - NonCanonicalMonad #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions message-index/messages/GHC-22705/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Noncanonical ‘return’ definition detected
summary: "'return', or '>>' not defined in terms of 'pure' or '*>'."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
summary: "'return', or '>>' not defined in terms of 'pure' or '*>'."
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use Markdown backticks instead of single quotes?..

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 '(*>)'.
13 changes: 13 additions & 0 deletions message-index/messages/GHC-22705/return/after/Return.hs
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions message-index/messages/GHC-22705/return/before/Return.hs
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions message-index/messages/GHC-22705/return/index.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions message-index/messages/GHC-22705/shortfish/after/Shortfish.hs
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions message-index/messages/GHC-22705/shortfish/before/Shortfish.hs
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions message-index/messages/GHC-22705/shortfish/index.md
Original file line number Diff line number Diff line change
@@ -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.