Looking for resources about more complex generics, comptime type construction, etc.

2022-12-21 Thread Hlaaftana
The reason `array[X.N, int]` doesn't work is because of the quirkiness of the array type, `array[0 .. X.N-1, int]` works.

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-21 Thread shirleyquirk
Too long already but I reread your post and realized I got a bit lost in the weeds. What I believe you were actually asking for was a way to provide an API to get out these compile time values. The actual answer is, they don't belong to the variable, they belong to the type. They are like

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-21 Thread shirleyquirk
Your exploration is really good, and there are in fact some things you can reason about. I don't want you to walk away thinking that the compiler is just completely fickle. Your `alt13` is actually a good illustration of it making sense. Even though I've seen confusion on the issue tracker as

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-21 Thread giaco
Thanks for all this fiddling with generics and type classes. I'm also stuck with this type of problems and running into inconsistencies between two apparently equal piece of VM code

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-20 Thread ElegantBeef
Technically by association does track this, but no clue if there is a concrete issue for it.

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-20 Thread auxym
I also hit this issue recently. Do you know if there is a github issue already tracking this?

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-20 Thread ElegantBeef
Yea statics have some bugs, so that's why it's so inconsistent. I believe the crux of the issue here is that when the VM runs code it does not return `static T` but instead `T` which means it fails on attempt to use with `static T`. There is a similar issue with field access on static objects

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-20 Thread fsh
I am taking from this that learning Nim generics/static[x] is about exploring and investigating? Here's one such exploration: # Setup: I have some macro that takes a static[int] import std/macros macro foo*(d: static[int]): untyped = newLit(d) # And a type that

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-20 Thread fsh
& another exploration: type FooType = enum ftA, ftB Foo[N: static[int]] = object typ: FooType # first guess: doesn't work! # # Test1[X: static[Foo]] = object # when X.typ == ftA: # Error: undeclared field: 'typ' for type

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-19 Thread ElegantBeef
Indeed: type A[T] = object var a: A[int] echo a.T Run

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-19 Thread giaco
Generic parameters can be accessed as fields?

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-19 Thread ElegantBeef
Well you wanted a collection, and the only collection I like using is `openarray` :P Jokes aside a `static seq`, `static openarray`, and `static array` are all identical in the compiler/vm, so the most flexible solution is `openarray`.

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-19 Thread fsh
I didn't see the later part of your message! Did you add that in or did I just miss it. > And yeah, re: question 3 I couldn't convince the compiler to accept an > expression there, I got: "Error, cannot generate code for: M" and wrote an > omfg proc in frustration. This is, also, part of

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-19 Thread fsh
> You could make a type alias for the first part Yes, you're right, tho again I admit my example was a bit stupid, as I put a concrete `int` there but actually is kind of what remains generic, I just wanted to "focus" on certain parameters. Like a typeclass-alias, rather than a type alias.

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-19 Thread ElegantBeef
You could make a type alias for the first part type MyComplexGeneric[X;Y;Z;W] = object MyRelaxedGeneric[X;Y;Z;] = MyComplexGeneric[int, float, string, int] Run The latter you could likely use a macro cache and cache a type for your special arrays.

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-19 Thread fsh
Hey, thanks so much for reply. > proc doThing(gen: MyGeneric) = discard # A generic type without parameters is > a typeclass Yep, this I got; I think of `MyGeneric = forall x, y: MyGeneric[x, y]`, but I meant if there's a way of getting `MyGenericIntLike = forall x: MyGeneric[x, int]`? Like a

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-19 Thread ElegantBeef
To work through this list a bit type MyGeneric[A;B;C;D: static int, E: static float] = object proc doThing(gen: MyGeneric) = discard # A generic type without parameters is a typeclass Run 3 is a compiler bug. I think a more sensible approach to last type is

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-19 Thread shirleyquirk
> Often I also get very confusing error messages (or even hit internal > assertions in the compiler) If you're crashing the compiler, you've found a bug! Search for it in the issue tracker on GitHub, see if someone's reported it already, and if so, add your test case to the comments. If not,

Looking for resources about more complex generics, comptime type construction, etc.

2022-12-19 Thread fsh
I am often in need of types which can carry a lot (or more complex) static compile-time information, à la: type SomeType[A: static[...], B: static[...], C: static[...], ...] = object ... Run I'm in general looking for some resources / documentation that goes more in