Idea: Allow underscore-prefixed identifiers
In Haskell, prefixing an identifier with an underscore is allowed. E.g. the following snippet compiles in Haskell, but not in Curry:
_test :: Int
_test = 3
Anonymous.curry:3:2 Error:
Unexpected token identifier `test'
|
3 | _test :: Int
| ^
Such identifiers could be useful for a variety of reasons:
- In Haskell, a common pattern is to name the implementation of a function (possibly taking additional parameters)
_f
and the exported, public interface functionf
- In Haskell, underscore-prefixed identifiers can be used to silence warnings about unused parameters. This could be useful if a parameter is explicitly to be marked as unused, but still assigned a name. For example:
const :: a -> b -> a
const x _y = y
would not emit a warning in Haskell. There is an additional challenge that this example shows, however:
Allowing underscore-prefixed identifiers is a breaking change, since the current Curry parser reads the function above as
const x _ y = y
(and thus throws a type error). If we were to implement a change that allows such identifiers, e.g. the following snippet would no longer be valid Curry:
const2 :: a -> b -> c -> a
const2 x _y = x
Same goes for the (currently) equivalent spelling
const2 :: a -> b -> c -> a
const2 x __ = x
While such formatting is usually considered unidiomatic, if we were to implement this feature, we should detect such cases and emit a descriptive error message along with a fix to rewrite the function as:
const2 x _ _ = x