swi-prolog 中的 Prolog 类型定义

发布于 2024-09-27 20:11:43 字数 154 浏览 4 评论 0原文

在可视化 prolog 中,prolog 程序中有一个“域”部分,您可以在其中定义类型。 swi-prolog中有类似的东西吗?

在可视化序言中,类型定义如下:

domains
NewType = thing1; thing2

in visual prolog there is "domains" section in a prolog program in which you can define types. Is there any similar thing in swi-prolog?

In visual prolog a type is defined like:

domains
NewType = thing1; thing2

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

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

发布评论

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

评论(3

荒岛晴空 2024-10-04 20:11:43

不会。但是 Mercury 中有模式声明。 Mercury 不仅仅是 Prolog;它是一种功能逻辑语言。 Mercury 仍然有很多 Prolog 语法。

SWI-Prolog 是一个标准的 Prolog。它仅使用文档中的模式声明1 作为用户信息。此类声明可以放置在模块的注释中,以便编译文档解析程序。

在标准 Prolog 中,除了注释之外,此类声明仅在非常特殊的情况下才允许(并且需要)。 区块例如,Sicstus Prolog 的谓词就需要它们。

Block/1 用于协同路由(惰性求值、延迟等)。我一生中只见过在一个程序中使用 block,PAKCS2,另一种功能逻辑语言的解释器。当解释器移植到SWI时,没有使用block/1

1 SWI 源文档中的类型和模式声明
2 PAKCS,使用 block/1 谓词(PAKCS 是 curry 语言的实现。)

No. But there is mode declaration in Mercury. Mercury is more than Prolog; it is a functional-logic language. Mercury still has a lot of Prolog syntax.

SWI-Prolog is a standard Prolog. It only uses mode declarations in documentation1 as information for the users. Such declarations can be placed in comments of modules for documentation-parsing programs to compile.

In standard Prologs, outside of comments, such declarations are only allowed (and reqired) in very special situations. The block predicate of Sicstus Prolog for instance requires them.

Block/1 is used for co-routing(lazy evaluation, delay etc.). I've only seen block used in one program in my life, PAKCS2, an interpreter for another functional-logic language. When the interpreter was ported to SWI, block/1 was not used.

1 Type and mode declarations in SWI Source Documentation
2 PAKCS, a program using the block/1 predicate (PAKCS is an implementation of the curry language.)

西瓜 2024-10-04 20:11:43

虽然 SWI-Prolog 不支持您所要求的类型,但值得注意的是,它确实通过 record/1 record 库中的谓词。

该谓词允许您使用特定术语规范语言指定相当复杂的术语“类型”(模式),并将其解释为自动生成用于执行创建(通过构造函数谓词)、通过“setter”谓词和访问器进行修改的谓词术语实例上的“getter”谓词,全部通过具有特定谓词命名约定的术语扩展来实现。

这在编写传递相当复杂的术语结构的 Prolog 代码时特别有用,因为它为您提供了 Prolog 通常(本身)缺乏的基本类型检查功能。我在许多大型 Prolog 项目中使用过它,其中接口是在实现之前设计的。

While SWI-Prolog doesn't support types in a capacity quite like what you're asking for, it is worth noting that it does indeed support a simple 'type' mechanism through the use of term specification via the record/1 predicate in the record library.

This predicate allows you to specify a reasonably complex term 'type' (pattern) using a particular term specification language, and interprets it to automatically generate predicates used to perform creation (via a constructor predicate), modification via 'setter' predicates and accessors via 'getter' predicates on term instances, all by way of term-expansion with a particular predicate naming convention.

This is particularly useful when writing Prolog code that passes around reasonably complex term structures, as it provides you with a rudimentary type checking capability which Prolog typically lacks (natively). I've used this on many a large-scale Prolog project where interfaces are designed before implementation.

一桥轻雨一伞开 2024-10-04 20:11:43

我记得读过有关 Swi & 类型的文章。序言。这是一个带有“Prolog 的 Hindley-Milner 类型检查器:”

类型的 网站Prolog - Mercury 风格的类型声明和谓词签名

Prolog 类型检查器库

I remembered reading about types for Swi & Yap prolog. Here's a website with a "Hindley-Milner Type Checker for Prolog:"

Types for Prolog - Mercury-style type declarations and predicate signatures

Prolog Type Checker library

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