Mercury 中不受限制的变量名称声明
我想在 Mercury 中声明一种数据类型,它可以具有可变数量的值和名称。例如:
type goal ---> pick; give; come.
具有三个变量/值。
我想要这样的东西:
type myplayer ---> de value declaration here.
变量的数量不受限制或固定。
因此,我可以使用 myplayer 来声明诸如 v1、v2、v3 和 v4 之类的值/变量。
第二次我可以使用它来声明类似以下内容:a、b、c、d、e 、z、aa、ab 和 az
。
值的数量不受限制,名称也不固定。
我是水星的新人。
I would like to declare a data type in Mercury that can have a variable number of values and names. For instance :
type goal ---> pick; give; come.
has three variables/values.
I want something like:
type myplayer ---> de value declaration here.
That's the number of variables are not restricted or fixed.
So I can use myplayer to declare values/variables like v1, v2, v3 and v4.
The second time I can use it to declare something like: a, b, c, d, e, z, aa, ab and az
.
The number of the values are not restricted and the names are also not fixed.
I am new in Mercury.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如其他人所说,这在水星上根本不可能——这是故意的。
不过,如果您想要一个表达 v1 v2 v3... 等的类型,您可能想要的是:
该类型表达所有整数的 v,并且函数名称可用于“漂亮打印”此类型的值。
As others have said, this is simply impossible in Mercury - which is deliberate.
What you might want though, if you want a type that expresses: v1 v2 v3... etc is:
The type expresses v of all integers, and the function name can be used to 'pretty-print' values of this type.
你直接要求的,根本无法完成。给定
其他类型的问题只能通过在定义的位置扩展此类型并重新编译模块来添加 - 并进行许多其他更改,因为以前的确定性代码
在给定新问题类型时会失败。在编译时被告知您未能更新程序以反映添加“选择所有正确答案”类型的问题是您拥有问题类型的一个很好的部分原因,而不是说字符串列表
[["狐狸漂亮吗?", "true"], ["绿狐狸是____", "可爱!", "假", "虐待动物的证据"]] 您的题库。
你所要求的事情是无法完成的。然而,您真正想做的事情(您认为“类型数量可变”将是一种有用的手段)肯定可以通过其他方式来完成。我不知道那是什么方式,因为我无法从你的问题中看出你为什么要这样做。也许您会受益于阅读 受歧视的工会或类型类语言参考。
What you directly ask for, simply cannot be done. Given
additional kinds of questions can only be added by extending this type where it is defined, and recompiling the module - and making a lot of other changes, too, as previously deterministic code like
would fail when given your new question type. Being told at compile-time where you've failed to update your program to reflect the addition of a "pick-all-the-right-answers" type of question is a good part of the reason you have a question type at all, instead of say lists of strings
[["Are foxes pretty?", "true"], ["Green foxes are ____", "adorable!", "fake", "evidence of animal cruelty"]]
for your question bank.What you ask for cannot be done. However, what you actually want to do -- the end to which you thought 'variable numbers of types' would be an helpful means -- can surely be accomplished in some other way. I can't tell what way that is, as I can't tell why you wanted to do this from your question. Maybe you'd benefit from reading over discriminated unions or typeclasses in the language reference.
据我了解这个问题。你想要一些类似 Prolog 的行为。即没有类型化谓词。在静态类型系统中,您始终可以通过自己处理来实现此类行为。很多年前我在Turbo Prolog中看到过这样的例子(他们用Turbo/Visual Prolog实现了ISO prolog)。
考虑类似的事情(我不确定它是否正确):
As far as I understand this question. You want some Prolog-like behavior. I.e without typed predicates. In statically typed system you always can achieve such behavior by handling that by yourself. A lot of time ago I saw such example in Turbo Prolog (they implemented ISO prolog in terms of Turbo/Visual Prolog).
Consider something like (I'm not sure it is correct):