Back to Purescript

`IncorrectAnonymousArgument` Error

errors/IncorrectAnonymousArgument.md

latest928 B
Original Source

IncorrectAnonymousArgument Error

Example

purescript
module Example where

add = (_ + _)

mapArray = map _ [1, 2, 3]

Cause

In an operator section, like (_ + 1), an anonymous argument can be used only once.

Fix

In the case of multiple arguments, give them names:

purescript
add a b = (a + b)

or in the case of a normal function: Write the function as an operator using backticks:

purescript
mapArray = _ `map` [1, 2, 3]

Notes

  • While _ + _ will give this error; \a -> a + _ will not

  • If you really want to have multiple anonymous arguments, it can be achieved like this:

purescript
add = (((+) $ _) $ _)