nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.41k stars 1.47k forks source link

Allow `array[..., void]` #23555

Open arnetheduck opened 4 months ago

arnetheduck commented 4 months ago

Summary

Extend void handling to also allow array[..., void].

Description

In https://github.com/nim-lang/Nim/issues/23419#issuecomment-2037606887, it is noted that an array of void is not allowed - this unnecessarily burdens generic code since array of void gracefully can be handled the same way as an ordinary void type.

Since void has no data, it follows naturally that array of void also doesn't have any data. We allow void variables, so we should also allow array-of-void variables - they are useful to simplify generic code and can be used as compile-time information carriers for macros, dsl etc.

Alternatives

No response

Examples

No response

Backwards Compatibility

No response

Links

No response

litlighilit commented 4 months ago

Currently void is only valid for generic argument, function return type, etc, but not for any concrete type.

As a variable of void is invalid, an array of void cannot be valid...

mratsim commented 4 months ago

As a variable of void is invalid, an array of void cannot be valid...

I think @arnetheduck meant parameter

This is valid Nim and compiles

proc foo(v: void) =
  echo "compiles"

foo()
metagn commented 4 months ago

tuple[] serves a similar purpose but it doesn't get erased in the backend and it doesn't have a special meaning like void that makes it independent from the type system. Some discussion on changing void is on https://github.com/nim-lang/RFCs/issues/508 and https://github.com/nim-lang/Nim/pull/20609.