如何读取这个 OCaml 类型签名?

发布于 2024-09-09 18:00:19 字数 958 浏览 3 评论 0原文

我目前正在尝试一起使用 OCaml 和 GTK(使用 lablgtk 绑定)。然而,该文档并不是最好的,虽然我可以弄清楚如何使用大多数功能,但我仍坚持更改笔记本页面(切换到不同的选项卡)。

我发现 该功能我需要使用,但我不知道如何使用它。该文档似乎表明它位于 GtkPackProps.Notebook,但我不知道如何调用它。

此外,这个函数的类型签名与我之前见过的任何类型签名都不同。

 val switch_page : ([> `notebook ], Gpointer.boxed option -> int -> unit) GtkSignal.t

我认为它返回 GtkSignal.t,但我不知道如何将第一个参数传递给函数(括号中的整个部分)。

有没有人有一些示例代码显示如何更改笔记本页面,或者可以给我一些关于如何执行此操作的提示?

I'm currently experimenting with using OCaml and GTK together (using the lablgtk bindings). However, the documentation isn't the best, and while I can work out how to use most of the features, I'm stuck with changing notebook pages (switching to a different tab).

I have found the function that I need to use, but I don't know how to use it. The documentation seems to suggest that it is in a sub-module of GtkPackProps.Notebook, but I don't know how to call this.

Also, this function has a type signature different to any I have seen before.

 val switch_page : ([> `notebook ], Gpointer.boxed option -> int -> unit) GtkSignal.t

I think it returns a GtkSignal.t, but I have no idea how to pass the first parameter to the function (the whole part in brackets).

Has anyone got some sample code showing how to change the notebook page, or can perhaps give me some tips on how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃兔兔 2024-09-16 18:00:19

你发现的不是函数而是信号。您在其类型中看到的函数类型是页面切换发生时将调用的回调类型,但不会导致页面切换。

顺便说一句, switch_page 的类型被解读为:笔记本 [> 引发的信号 (GtkSignal.t) `notebook],其回调类型为 Gpointer.boxed 选项 ->整数-> unit

一般来说,使用lablgtk,你最好远离Gtk*低级模块,而使用tge G[AZ]更高级模块。这些模块 API 看起来像 C Gtk 的 API,我总是使用主要的 Gtk 文档来帮助自己。

在您的情况下,您想使用 GPack.notebook 对象及其 goto_page 方法。

What you have found is not a function but the signal. The functional type you see in its type is the type of the callback that will be called when the page switch happen, but won't cause it.

by the way the type of switch_page is read as: a signal (GtkSignal.t) raised by notebook [> `notebook ], whose callbacks have type Gpointer.boxed option -> int -> unit

Generally speaking, with lablgtk, you'd better stay away of the Gtk* low level modules, and use tge G[A-Z] higher level module. Those module API look like the C Gtk one, and I always use the main Gtk doc to help myself.

In your case you want to use the GPack.notebook object and its goto_page method.

仅一夜美梦 2024-09-16 18:00:19

您已经发现了一个多态变体;它们在手册第 4.2 节中进行了描述,并且输入规则总是让我头疼。我相信签名所说的是函数 switch_page 期望作为参数 GtkSignal.t,它是由两种类型参数化的抽象:

  • 第一个类型参数,

    <前><代码>[> `笔记本]

    包括任何多态变体作为值,包括 notebook(这就是大于的意思)。

  • 第二类型参数是普通函数。

如果我正确地阅读了 GtkSignal.t 的文档,它根本就不是一个函数;而是一个函数。它是一个包含三个字段的记录:

  • name 是一个字符串。
  • classe 是一个多态变体,可以是“notebook”或其他东西。
  • marshaller 是函数类型 Gpointer.boxed 选项 -> 的编组器整数->单位。

我希望这有帮助。如果您遇到更多麻烦,手册中有关多态变体的 4.2 节可能会帮您解决。

You've found a polymorphic variant; they're described in the manual in Section 4.2, and the typing rules always break my head. I believe what the signature says is that the function switch_page expects as argument a GtkSignal.t, which is an abstraction parameterized by two types:

  • The first type parameter,

    [> `notebook]
    

    includes as values any polymorphic variant including notebook (that's what the greater-than means).

  • The second type parameter is an ordinary function.

If I'm reading the documentation for GtkSignal.t correctly, it's not a function at all; it's a record with three fields:

  • name is a string.
  • classe is a polymorphic variant which could be ``notebook` or something else.
  • marshaller is a marshaller for the function type Gpointer.boxed option -> int -> unit.

I hope this helps. If you have more trouble, section 4.2 of the manual, on polymorphic variants, might sort you out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文