Skip to content

Commit c06de0d

Browse files
Merge pull request #346 from haskellfoundation/GHC-91938
Document GHC-91938
2 parents 2e96f97 + 6b268c0 commit c06de0d

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
f Nothing x = x
2+
f (Just y) x = y + x
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
f Nothing = \x -> x
2+
f (Just y) x = y + x
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Varying numbers of arguments
3+
---
4+
5+
In this example, the function `f` has type `Num a => Maybe a -> a -> a`. Even though each case of the definition can have this type on its own, one of them has a single argument to the left of the `=` and a lambda on the right-hand side, and the other has two arguments to the left of the `=`. In Haskell, each defining equation must have the same number of arguments prior to the `=`.
6+
7+
The program was fixed by moving the lambda's argument to the left of the `=`.
8+
9+
## Error Message
10+
11+
```
12+
Main.hs:1:1: error: [GHC-91938]
13+
Equations for ‘f’ have different numbers of arguments
14+
Prog.hs:2:1-19
15+
Prog.hs:3:1-20
16+
|
17+
2 | f Nothing = \x -> x
18+
| ^^^^^^^^^^^^^^^^^^^...
19+
```
20+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Equations have different number of arguments
3+
summary: Each equation in a function definition must have the same number of arguments.
4+
severity: error
5+
introduced: 9.6.1
6+
---
7+
8+
Haskell functions are defined using equations, with the function name and patterns on the left side of the `=` and expressions on the right side. When the function is applied, the patterns in the equations are checked from top to bottom, with the first matching equation being chosen.
9+
10+
Each equation that defines a function must have the same number of patterns to the left of the `=`.
11+
12+

0 commit comments

Comments
 (0)