gluon icon indicating copy to clipboard operation
gluon copied to clipboard

Ergonomic way to use Gluon type parameters in Rust

Open Laegluin opened this issue 6 years ago • 5 comments

With #600 you replaced most uses of Generic with for example OpaqueValue<RootedThread, generic::A>. Is this always necessary? If so it's probably best to make this more convenient to use (and maybe also hide some of the internals like all of the generic::* enums).

Laegluin avatar Aug 06 '18 13:08 Laegluin

I unfortunately had to change how Generic worked to make sure it was always safe to use which forced me to modify it. Before the next release I want to go through this whole api again though to further generalize and simplify these parts though but for the moment just using OpaqueValue<RootedThread, generic::A> should always work (you may want to define a type alias over it though).

and maybe also hide some of the internals like all of the generic::* enums

Not sure what you mean, the A,B... enums under generic are all meant to be part of the public api as it makes it possible to use multiple type variables in the same function.

Marwes avatar Aug 06 '18 20:08 Marwes

(You can still use Generic as a parameter at least but it is currently awkward to use as an output)

Marwes avatar Aug 06 '18 20:08 Marwes

Still a WIP but #607 is the rough idea.

For instance, it makes it possible to write array.index : Array a -> Int -> a entirely with rooted values https://github.com/gluon-lang/gluon/pull/607/files#diff-17448a895470d132de007f9f3c5bb485R28

Marwes avatar Aug 07 '18 10:08 Marwes

Looks really neat!

Does that mean you can use OpaqueRef<'a, generic::A> for parameters instead of Generic? In that case it's probably better to remove Generic completely. OpaqueRef seems more consistent to me, and it's a lot easier to understand why you need a wrapper in first place.

Laegluin avatar Aug 07 '18 10:08 Laegluin

Yep, that's the idea. I have already removed it in that PR and I will likely be able to remove a few more such wrappers as well.

Will explain it in the book after I am done as it should be an API I can actually feel good about stabilizing

Marwes avatar Aug 07 '18 11:08 Marwes