swi-prolog 中的 Prolog 类型定义
在可视化 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不会。但是 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.)虽然 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.
我记得读过有关 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