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

Auto-load custom printers in the OCaml toplevel. #448

Merged
merged 1 commit into from
Sep 20, 2016
Merged

Auto-load custom printers in the OCaml toplevel. #448

merged 1 commit into from
Sep 20, 2016

Conversation

yallop
Copy link
Owner

@yallop yallop commented Sep 20, 2016

Ctypes comes with a subpackage ctypes.top that provides custom printing for C types and values. At present ctypes.top needs to be explicitly loaded into the OCaml top level.

This PR auto-loads the custom printers whenever the ctypes package is loaded in the OCaml top level, making custom printing available by default.

Before:

# #require "ctypes";;
[...]
/home/jeremy/.opam/4.03.0/lib/ctypes/ctypes.cma: loaded
# Ctypes.(int @-> int @-> returning string);;
- : (int -> int -> string) Ctypes_static.fn =
Ctypes_static.Function (Ctypes_static.Primitive Ctypes_primitive_types.Int,
 Ctypes_static.Function (Ctypes_static.Primitive Ctypes_primitive_types.Int,
  Ctypes_static.Returns
   (Ctypes_static.View
     {Ctypes_static.read = <fun>; write = <fun>; format_typ = None;
      format = None;
      ty =
       Ctypes_static.Pointer
        (Ctypes_static.Primitive Ctypes_primitive_types.Char)})))

After:

# #require "ctypes";;
[...]
/home/jeremy/.opam/4.03.0/lib/ctypes/ctypes.cma: loaded
/home/jeremy/.opam/4.03.0/lib/ctypes/ctypes-top.cma: loaded
# Ctypes.(int @-> int @-> returning string);;
- : (int -> int -> string) Ctypes.fn = char*(int, int)

The ctypes.top subpackage is retained for compatibility reasons.

@yallop yallop merged commit 5f60273 into yallop:master Sep 20, 2016
@yallop yallop deleted the autoload-top branch September 20, 2016 17:29
@dbuenzli
Copy link
Contributor

Somehow I thought that way at a certain point but changed my mind see here dbuenzli/gg#1 for discussion.

I think that you should keep a way to load the library without side effects on the toplevel and it's more logical to keep the bare name for that and keep the convention of having packages PKG.top for toplevel features.

Now a reasonable enhanced toplevel would load the .top by convention if it exists and provide a way to prevent it from loading and use the bare library instead.

I really prefer if the bare package name, side-effect wise, denotes exactly the same as using the library.

FWIW this is the convention I implement in all my packages.

@dbuenzli
Copy link
Contributor

dbuenzli commented Sep 21, 2016

I forgot. Another benefit is that if you structure your packages the way I mentioned you can keep the idea that subpackages exactly correspond to cm[x]a files. Something I find reasonable in the long term for simplifying the build eco-system.

We should rather try convince toplevels to enforce conventions about loading and preventing to load PKG.top packages.

@yallop
Copy link
Owner Author

yallop commented Sep 21, 2016

Thanks, @dbuenzli. A toplevel convention to load .top packages by default would be useful.

The main problem identified in dbuenzli/gg#1 is the automatic and silent execution of open Gg. I can see how that would be a problem. But there's nothing like that here; the .top package installs printers, but does nothing else.

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

Successfully merging this pull request may close these issues.

2 participants