任意嵌套类型

发布于 2025-02-13 21:07:32 字数 415 浏览 0 评论 0原文

我试图提出一种创建任意深嵌套类型的方法,每个实例都取决于父母的类型,但我无法提出任何解决方案。

我正在考虑具有两个类型变量的类型t,其中第二个是t,哪个类型变量取决于其父。

data T a b = T (a -> b) (T (b -> c) (T (c -> d) ...))

我知道,从理论上讲,每个类型变量都应该出现在左侧和右侧,而且我不知道这是否可能是可能的,但是我想有某种方法可以做这项工作。

我在gadtsrankntypes之类的GHC扩展方面的经验非常有限,但据我所知,这将是对这些的用户酶?

I tried to come up with a way of creating a arbitrarily deep nested type where each instance depends on the type of it's parent, but I couldn't come up with any solution.

I was thinking about something like a type T with two type variables, where the second is itself a T which first type variable depends on its parent.

data T a b = T (a -> b) (T (b -> c) (T (c -> d) ...))

I know that in theory every type variable should appear on the left and right side, and I don't know if this is even possible at all, but I guess that there is some way of making this work.

My experience with GHC extensions like GADTs and RankNTypes is very limited but as far as I know this would be a usecase for those?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文