任意嵌套类型
我试图提出一种创建任意深嵌套类型的方法,每个实例都取决于父母的类型,但我无法提出任何解决方案。
我正在考虑具有两个类型变量的类型t
,其中第二个是t
,哪个类型变量取决于其父。
data T a b = T (a -> b) (T (b -> c) (T (c -> d) ...))
我知道,从理论上讲,每个类型变量都应该出现在左侧和右侧,而且我不知道这是否可能是可能的,但是我想有某种方法可以做这项工作。
我在gadts
和rankntypes
之类的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论