8000 Merge pull request #144 from csicar/patch-1 · purescript/documentation@37e28fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 37e28fb

Browse files
authored
Merge pull request #144 from csicar/patch-1
add documentation for IncorrectAnonymousArgument
2 parents 1e5a59e + f62b797 commit 37e28fb

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

errors/IncorrectAnonymousArgument.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,35 @@
33
## Example
44

55
```purescript
6-
module ShortFailingExample where
6+
module Example where
77
8-
...
8+
add = (_ + _)
9+
10+
mapArray = map _ [1, 2, 3]
911
```
1012

1113
## Cause
1214

13-
Explain why a user might see this error.
15+
In an [operator section](https://github.com/purescript/documentation/blob/fc4a9db4b128aa3331e5f990cb1860e59077af31/language/Syntax.md#operator-sections), like `(_ + 1)`, an anonymous argument can be used only once.
16+
1417

1518
## Fix
1619

17-
- Suggest possible solutions.
20+
In the case of multiple arguments, give them names:
21+
```purescript
22+
add a b = (a + b)
23+
```
24+
or in the case of a normal function: Write the function [as an operator](https://github.com/purescript/documentation/blob/fc4a9db4b128aa3331e5f990cb1860e59077af31/language/Syntax.md#functions-as-operators) using backticks:
25+
```purescript
26+
mapArray = _ `map` [1, 2, 3]
27+
```
28+
1829

1930
## Notes
2031

21-
- Additional notes.
32+
- While `_ + _` will give this error; `\a -> a + _` will not
33+
34+
- If you really want to have multiple anonymous arguments, it can be achieved like this:
35+
```purescript
36+
add = (((+) $ _) $ _)
37+
```

0 commit comments

Comments
 (0)
0