Skip to content
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

Re-export hand-written bindings for basic types in the expected places #315

Open
istathar opened this issue Sep 9, 2020 · 3 comments
Open

Comments

@istathar
Copy link

istathar commented Sep 9, 2020

Quick one: should

import Data.GI.Base

have resulted in the GType being in scope? I was mildly surprised I had to

import Data.GI.Base.GType

explicitly before using GType when making a GtkListView.

(the blanket

import qualified GI.Gtk as Gtk

brings in everything; wondering if you'd like the Glib base stuff to be similar?)

@garetxe
Copy link
Collaborator

garetxe commented Sep 19, 2020

Thanks! (And sorry for the slow reply!)

This is on purpose, but I agree that it is confusing. The autogenerated bindings export everything because the intended usage is by importing qualified, as you did. It is then convenient to do Gtk.Button, Gtk.Label and so on, instead of having to import each submodule separately.

Data.GI.Base, on the other hand, is slightly different: it exports the basic syntax for using the bindings effectively: on, new, set, :=, and so on. It is quite a pain having to prefix all these, hence it is intended that you just import Data.GI.Base unqualified to have this vocabulary available.

But in order to avoid polluting the namespace too much, Data.GI.Base only re-exports the things that are commonly used (in my experience at least :) ). Perhaps an arbitrary distinction, but at its core the reason for the difference is the one above.

If you check the things that are actually exported, you'll find that not everything being exported from Data.GI.Base is too important. This is mostly historical: when I started writing the library I defaulted to exporting everything. But I now think that that was a mistake, and I have been trying not to export anything further by default (unless I thought it was essential).

Does this sound reasonable?

@istathar
Copy link
Author

@garetxe maybe go for consistency? ie if we have to

import qualified GI.Gtk as Gtk

then perhaps we should also have to do

import qualified GI.Glib as G

although I just realized in a ghci session that Gtk.GType is in scope. Not sure how I missed that. So maybe this wasn't something I should have reported.

@garetxe
Copy link
Collaborator

garetxe commented Sep 20, 2020

This would make sense, but note that GType in haskell-gi is not autogenerated, but rather there are hand-written bindings. But perhaps we should re-export those as part of the gi-gobject bindings, which would implement what you suggest.

There is currently no support for adding hand-written code to autogenerated bindings, but I was planning to add it. I will keep this issue open as a reminder to add the re-export for GType once this is done.

@garetxe garetxe changed the title Should Data.GI.Base re-export its submodules? Re-export hand-written bindings for basic types in the expected places Sep 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants