方案 - 关于新类型的一般问题
我们能否在Scheme中定义新类型,以便Scheme能够识别它们并 强制执行它们的不变量?
换句话说,当我定义圆的ADT(make_circle、get_radious等)时,我可以在Scheme中将它用作新类型吗?
Can we define new types in Scheme such that Scheme will recognize them and
enforce their invariants?
In other words, when I define, for example, ADT for circle (make_circle, get_radious, etc..), I can use it in Scheme as a new type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SRFI-9 定义 Define-record-type 宏。大多数方案都有定义记录、定义结构或类似的变体,我认为这是定义记录类型的简化。
然后许多方案都有某种类型的类似 CLOS 的对象系统,例如 tinyclos 或 Chicken 的 < a href="http://wiki.call-cc.org/eggref/4/coops" rel="nofollow">Coops - 两者都实现了多种方法,这非常好。
使用 SRFI-9 的示例:
然后在您的 REPL 中:
SRFI-9 defines the define-record-type macro. Most schemes have a variant of define-record, define-struct or something similar which I believe is a simplification of define-record-type.
And then many schemes have some type of CLOS-like object system, such as tinyclos or Chicken's Coops - both of which implement multimethods, which is quite nice.
Example Using the SRFI-9:
Then in your REPL:
球拍具有强大的类型系统。此外,
define-struct
在方案中也得到了很好的支持。Racket has powerfull type system. Also
define-struct
is well supported among schemes.