有没有任何编程语言可以让您重新定义其类型系统?

发布于 2024-09-25 17:23:55 字数 67 浏览 0 评论 0原文

我正在寻找一种编程语言,可以让您重新定义其类型系统,而无需侵入编译器。有什么东西可以让你这样做吗?

谢谢

I'm looking for programming languages that let you redefine their type system without having to hack into the compiler. Is there anything out there that allows you to do that?

Thanks

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

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

发布评论

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

评论(4

我是男神闪亮亮 2024-10-02 17:23:55

在 C 中,您可以使用 DEFINE 重新定义所有内容。

#DEFINE int double

无论是好是坏,您都可以在这里找到:

您遇到过的最严重的现实世界宏/预处理器滥用是什么?

In C you can use DEFINE to redefine everything.

#DEFINE int double

Whether it's good or bad you can find out here:

What is the worst real-world macros/pre-processor abuse you've ever come across?

夜灵血窟げ 2024-10-02 17:23:55

如果您正在谈论重新定义实际类型系统,例如使静态类型语言变得动态或使弱类型语言成为强类型,那么不行。

实际上每种语言都允许您定义自己的类型,所以我认为这也不是您的意思。

我能想到的唯一可能符合您所问问题的是 Common Lisp 中的宏,它可以让您扩展语法。这可能能够实现您正在寻找的东西,但是在您明确说明您正在寻找的东西之前,我无法详细说明。

OCaml 及其相关语言还允许您使用类型做一些非常酷的事情。您基本上可以定义您能想到的任何类型,然后通过模式匹配对其进行匹配,这使得编写编译器特别好。

If you're talking about redefining an actual type system, like making a statically typed language dynamic or making a weakly-typed language strongly-typed, then no.

Practically every language lets you define your own types, so I don't think that's what you meant either.

The only thing I can think of that might fit into what you're asking about are Macros in Common Lisp, which let you extend the syntax. This might be able to acheive what you are looking for, but until you state what it is exactly you're looking for, I can't really elaborate.

Also OCaml and its related languages allow you to do some pretty cool things with types. You can basically define any kind of type you can think of and then match against it with pattern matching, which makes it especially good to write compilers in.

篱下浅笙歌 2024-10-02 17:23:55

据我所知,Javascript、Ruby 和 Smalltalk 允许您执行各种操作,甚至可以动态重新定义对象可以执行的操作。 Perl 允许您重新定义几乎整个语言。基本上任何像样的脚本语言,尤其是允许鸭子类型的脚本语言,都应该具有相同的功能。但它似乎在函数式语言和具有函数式能力的语言中确实很常见。

Javascript, Ruby, and Smalltalk, just that i know of, allow you to do all kinds of stuff, even redefining on the fly what an Object can do. Perl allows you to redefine practically the whole language. Basically any decent scripting language, especially one that allows duck typing, should have equal power. But it seems to be really common among functional languages and those with functional abilities.

七度光 2024-10-02 17:23:55

如果我没记错的话,Ada 具有简洁的类型创建可能性,特别是对于度量(例如,定义最小值和最大值、检查不同度量之间的操作......)。我已经看到它被引用作为一个例子来避免非常愚蠢的错误。

If I remember correctly, Ada have neat type-creation possibilities, specially for measures (for instance, defining a minimum and a maximum, checking operations between differents measures...). I've seen it quoted as an example to avoid very stupid bugs.

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