Square brackets for generics

2020-11-15 Thread AmjadBHD
why not use `a[:T]` instead of `a!T`, it's closer to the current syntax.

Square brackets for generics

2020-11-05 Thread Araq
> It allows you to know at parse time that it's a generic instantiation, > instead of after semantic phase. This is a big deal, as it would allow macros > to know that some AST refers to a generic instantiation vs array indexing, > whereas all you get now is the ambiguous nnkBracketExpr This is

Square brackets for generics

2020-11-05 Thread timothee
> That's one of these D myths as far as I'm concerned. It's still ambiguous, > consider (Y) ! x, is that a type cast plus a unary ! operator or a generic > instantiation? it's not ambiguous. void fun(T)(int a){} void main(string[]args){ (fun)!double(3); // Error: C style

Square brackets for generics

2020-11-05 Thread Sixte
Well, we already left Nim <1.0 behind and the "free running" or strictly local type parameters are here to stay with the [T] notation. It might be interesting to think about module-wide type parameters though (extended scope). With concept[T], we have (in principle) these in Nim. Haskell has typ

Square brackets for generics

2020-11-05 Thread Araq
That's one of these D myths as far as I'm concerned. It's still ambiguous, consider `(Y) ! x`, is that a type cast plus a unary `!` operator or a generic instantiation? (Plus the syntax is ugly.)

Square brackets for generics

2020-10-29 Thread timothee
D has the best syntax here, a!T, a.b!T, a![T1,T2] No ambiguity between normal and UFCS, and shorter syntax for the common case.

Square brackets for generics

2020-10-29 Thread Araq
> None of these are perfect, ... So why change anything... ;-)

Square brackets for generics

2020-10-29 Thread gemath
> Well you can call printSqured(b) and have its T inferred and that makes all > the difference. True. Two different ways around this: * calling it like this `printSquared()(b)` to indicate the inferred first parameter list (sucky IMHO) or * defining it in upper-case proc Pri

Square brackets for generics

2020-10-27 Thread Hlaaftana
> The most common point brought up is that expressions like > foo[x](https://forum.nim-lang.org/postActivity.xml) would be ambiguous The angle bracket version of this isn't great either, in Rust you have to do `foo::()`, and Java requires you to do `Class.foo()`. Nim could easily enforce `foo[:

Square brackets for generics

2020-10-27 Thread Araq
> Solitude is right, but there is another problem with square brackets together > with UFCS in Nim - a.b[T](https://forum.nim-lang.org/postActivity.xml) > doesn't work, for that a new syntax extension was introduced - > a.b[:T](https://forum.nim-lang.org/postActivity.xml) so it's not ambiguou T

Square brackets for generics

2020-10-27 Thread Araq
Well you can call `printSqured(b)` and have its `T` inferred and that makes all the difference.

Square brackets for generics

2020-10-27 Thread gemath
IMHO, in a meta-programming-heavy language like Nim, there shouldn't even be a special type of bracket used for generic type parameters, `()` is good enough. A "generic" just returns a concrete `type` or `proc` when called with type parameters at compile time. The syntax element for call paramet

Square brackets for generics

2020-10-26 Thread Yardanico
Solitude is right, but there is another problem with square brackets together with UFCS in Nim - a.b[T](https://forum.nim-lang.org/postActivity.xml) doesn't work, for that a new syntax extension was introduced - a.b[:T](https://forum.nim-lang.org/postActivity.xml) so it's not ambiguous.

Square brackets for generics

2020-10-26 Thread xigoi
Well, you can't determine that at parse time. Which leads me to believe that this is possible in Nim precisely because Nim's parser doesn't need to distinguish between types and values, unlike other languages.

Square brackets for generics

2020-10-26 Thread SolitudeSF
how is that ambiguous? one is collection, other is function.

Square brackets for generics

2020-10-26 Thread xigoi
On many programming subreddits, there are arguments about using square brackets[] for generics instead of the cumbersome angle<> brackets, particularly in Rust and Go. The most common point brought up is that expressions like `foo[x]()` would be ambiguous — is it a generic function call,