Skip to content

Commit ce45359

Browse files
fendorBinderDavid
authored andcommitted
Add message for GHC-06201
1 parent 5bb2f29 commit ce45359

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module A where
2+
3+
class Calculator a where
4+
add :: a -> a -> a
5+
multiply :: a -> a -> a
6+
7+
instance Calculator Int where
8+
add a b = a + b
9+
multiply a b = a * b
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module A where
2+
3+
class Calculator a where
4+
add :: a -> a -> a
5+
multiply :: a -> a -> a
6+
7+
instance Calculator Int where
8+
add a b = a + b
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: No explicit implementation for method instance
3+
---
4+
5+
## Error Message
6+
7+
```
8+
A.hs:7:10: warning: [GHC-06201] [-Wmissing-methods]
9+
• No explicit implementation for
10+
‘multiply’
11+
• In the instance declaration for ‘Calculator Int’
12+
|
13+
7 | instance Calculator Int where
14+
```
15+
16+
## Explanation
17+
18+
The type class `Calculator` requires you to implement two methods: `add` and `multiply`.
19+
However, the example instance `instance Calculator Int` only implements the method `add` and not `multiply`
20+
To fix this, implement the method `multiply`!
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module A where
2+
3+
data Box t = SomeBox t
4+
5+
instance Functor Box where
6+
fmap f (SomeBox a) = SomeBox (f a)
7+
8+
instance Applicative Box where
9+
pure a = SomeBox a
10+
SomeBox f <*> SomeBox a = SomeBox (f a)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module A where
2+
3+
data Box t = SomeBox t
4+
5+
instance Functor Box where
6+
fmap f (SomeBox a) = SomeBox (f a)
7+
8+
instance Applicative Box where
9+
pure a = SomeBox a
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: No explicit implementation for method instance 2
3+
---
4+
5+
## Error Message
6+
7+
```
8+
A.hs:8:10: warning: [GHC-06201] [-Wmissing-methods]
9+
• No explicit implementation for
10+
either ‘<*>’ or ‘liftA2’
11+
• In the instance declaration for ‘Applicative Box’
12+
|
13+
8 | instance Applicative Box where
14+
| ^^^^^^^^^^^^^^^
15+
```
16+
17+
## Explanation
18+
19+
The type class `Applicative` requires you to implement at least two methods:
20+
21+
* `pure`, and
22+
* `liftA2` or `multiply` (can also be both).
23+
24+
Such `or` constraints can be expressed via the [`{-# MINIMAL #-}`](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/pragmas.html#minimal-pragma) pragma.
25+
26+
To fix this, either implement the method `liftA2` or `<*>`. For this example, we implemented `<*>`, but either or both is fine, too.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Missing method in type class instance
3+
summary: A required method is missing from the instance declaration.
4+
severity: warning
5+
flag: -Wmissing-methods
6+
introduced: 9.6.1
7+
---
8+
9+
This warning means that a type class instance is missing some required method implementations.

0 commit comments

Comments
 (0)