-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instantiate backpack signatures when importing #599
Comments
Great to see this, I really like backpack and also want it to thrive more. I'd add to the list of reasons blocking it from being more widely used:
|
That's a good point. I haven't ever tried using Backpack with HLS. That might also be a good thing to open a bug report about. I can only find this one relating to Also, I should say that I don't think what I'm proposing removes the need for specifying something like: signatures: A In the cabal file. So this may not solve that issue with HLS directly. |
Suppose there were modules Would we need to replicate the same instantiations (the In the current cabal-based syntax for mixins, that wouldn't be needed. It would be something like
In Backpack, instantiation works at the level of entire libraries, not individual modules. |
That's right. One way to get close at an import level would be to create a stub module: module X (module B, module C, module D) where
import B
import C
import D And then instantiate import qualified X as XHello where A = Hello
import qualified X as XGoodbye where A = Goodbye Of course now you don't have the fine-grained You could consider a syntax like: instantiate A = Hello in
import qualified B as BHello
import qualified C as CHello
import qualified D as DHello But I don't know if that is worth it. The duplication does not seem that bad to me. Edit: And I should mention that I'm not proposing to remove mixins. This |
I'm actually coming around to the let-style syntax instead of where-style, e.g.: let A = Hello in
import qualified B as BHello Being able to instantiate multiple modules at the same time is a big advantage. For example @alt-romes' https://github.com/alt-romes/ghengin/ could use this syntax in Main.hs: let
Ghengin.Core.Renderer.Kernel = Ghengin.Vulkan.Renderer.Kernel
Ghengin.Core.Renderer.DescriptorSet = Ghengin.Vulkan.Renderer.DescriptorSet
Ghengin.Core.Renderer.Buffer = Ghengin.Vulkan.Renderer.Buffer
Ghengin.Core.Renderer.Pipeline = Ghengin.Vulkan.Renderer.Pipeline
Ghengin.Core.Renderer.RenderPass = Ghengin.Vulkan.Renderer.RenderPass
Ghengin.Core.Renderer.Texture = Ghengin.Vulkan.Renderer.Texture
Ghengin.Core.Renderer.Sampler = Ghengin.Vulkan.Renderer.Sampler
in
import Ghengin
import Ghengin.Core.Mesh
import Ghengin.Component.Camera
import Ghengin.Component.Transform
import Ghengin.Component.UI
import Ghengin.Core.Render.Packet
import Ghengin.Scene.Graph
import Ghengin.Core.Render.Property I expect having such a block in Main will become quite a common pattern. |
An alternative to the let-style syntax is to allow mix-in style matching, so that when you write import qualified Ghengin.Vulkan.Renderer.Kernel as Ghengin.Core.Renderer.Kernel
import qualified Ghengin.Vulkan.Renderer.DescriptorSet as Ghengin.Core.Renderer.DescriptorSet
import qualified Ghengin.Vulkan.Renderer.Buffer as Ghengin.Core.Renderer.Buffer
import qualified Ghengin.Vulkan.Renderer.Pipeline as Ghengin.Core.Renderer.Pipeline
import qualified Ghengin.Vulkan.Renderer.RenderPass as Ghengin.Core.Renderer.RenderPass
import qualified Ghengin.Vulkan.Renderer.Texture as Ghengin.Core.Renderer.Texture
import qualified Ghengin.Vulkan.Renderer.Sampler as Ghengin.Core.Renderer.Sampler
import Ghengin
import Ghengin.Core.Mesh
import Ghengin.Component.Camera
import Ghengin.Component.Transform
import Ghengin.Component.UI
import Ghengin.Core.Render.Packet
import Ghengin.Scene.Graph
import Ghengin.Core.Render.Property By itself this means you can't easily instantiate the same signature with two different modules, but in that case you can use the Edit: Or a combination: let
import Ghengin.Vulkan.Renderer.Kernel as Ghengin.Core.Renderer.Kernel
import Ghengin.Vulkan.Renderer.DescriptorSet as Ghengin.Core.Renderer.DescriptorSet
import Ghengin.Vulkan.Renderer.Buffer as Ghengin.Core.Renderer.Buffer
import Ghengin.Vulkan.Renderer.Pipeline as Ghengin.Core.Renderer.Pipeline
import Ghengin.Vulkan.Renderer.RenderPass as Ghengin.Core.Renderer.RenderPass
import Ghengin.Vulkan.Renderer.Texture as Ghengin.Core.Renderer.Texture
import Ghengin.Vulkan.Renderer.Sampler as Ghengin.Core.Renderer.Sampler
in
import Ghengin
import Ghengin.Core.Mesh
import Ghengin.Component.Camera
import Ghengin.Component.Transform
import Ghengin.Component.UI
import Ghengin.Core.Render.Packet
import Ghengin.Scene.Graph
import Ghengin.Core.Render.Property |
Backpack is not used enough. I think there are two main reasons for this which we can address with a GHC proposal:
I think both these points can be addressed by integrating Backpack more tightly into the language. In particular, I'd propose we allow instantiating Backpack signatures when importing modules. The syntax could look like this:
As you might expect, this program would print:
Notes:
E.g. in the example above you could create a module
C
that importsB
without instantiatingA
, as long as the module that importsC
does instantiateA
(or if there is again another module aboveC
that instantiatesA
).E.g. we could create a new signature
C.hsig
and writeimport qualified B as BC where A = C
as long asC
is then eventually instantiated too.E.g.
import qualified Hello
andimport qualified Goodbye
in the example above.import ... where ...
block.E.g.
import W where X = Foo; Y = Bar; Z = Baz
or over multiple lines following the layout rules.where ...
part must always be at the end of theimport ...
line. This is intended to make it easier to parse.These changes are meant to make it easier for Stack to support a minimally usable version of Backpack, because under this proposal GHC can handle most of the instantiation on its own (as long as the proper modules and signatures are supplied). Furthermore, this makes Backpack much more at hand. Using a signature becomes as simple as writing a
.hsig
file, importing that in a module, and instantiating that module when it is imported. No more messing around with local libraries in cabal files or mixins.The text was updated successfully, but these errors were encountered: