Java 中的 Haskell 类型类层次结构

发布于 2024-11-09 19:43:40 字数 1029 浏览 5 评论 0原文

我编写了一个,其中包含类似于 Haskell 类型类的 Java 接口,以及实现所有“可派生”的抽象类方法(例如,可以使用 >>=return 编写 Monad.join)。这是我计划的结构([]表示接口尚不存在):

                      Applicative <= Alternative <-,     
Functor <= Pointed <= Applicative <= Monad <= MondPlus
Functor <= Copointed <= Comonad      Monad <= [MonadFix]

Category <= Arrow <= ArrowChoice   
            Arrow <= [ArrowApply]
            Arrow <= [ArrowLoop] 
            Arrow <= [ArrowZero] <= [ArrowPlus]
Bifunctor
  • 这个层次结构“正确”吗?
  • 特别是 MonadPlus 实现 Alternative 是否正确?
  • 我应该将 MonadZero 从 MonadPlus 中分离出来吗?同样的问题 ArrowZero 和 ArrowPlus
  • 当一个类实现多个“端点”时(例如 Maybe 是 MonadPlus 和 MonadFix,Kleisli 是 ArrowEverything),如何减少代码重复
  • Arrow 理论上也可以扩展 Applicative。目前,我在 Arrow 上有一个返回 Applicative 的方法,因为看起来类型循环使得继承在这里变得不可能。
  • 我还缺少其他不明显的“连接”(如箭头->应用)吗?
  • 此层次结构中缺少哪些“有用”类型类?

I write a library with Java interfaces resembling Haskell type classes, and abstract classes implementing all "derivable" methods (e.g. Monad.join can be written using >>= and return). This is my planned structure ([] means the interface doesn't exist yet):

                      Applicative <= Alternative <-,     
Functor <= Pointed <= Applicative <= Monad <= MondPlus
Functor <= Copointed <= Comonad      Monad <= [MonadFix]

Category <= Arrow <= ArrowChoice   
            Arrow <= [ArrowApply]
            Arrow <= [ArrowLoop] 
            Arrow <= [ArrowZero] <= [ArrowPlus]
Bifunctor
  • Is this hierarchy "correct"?
  • Particularly, is it correct that MonadPlus implements Alternative?
  • Should I split MonadZero from MonadPlus? Same question for ArrowZero and ArrowPlus
  • How can I reduce code duplication when a class implements multiple "endpoints" (e.g. Maybe is a MonadPlus and a MonadFix, Kleisli is ArrowEverything)
  • Arrow could theoretically extend Applicative as well. Currently I have a method on Arrow returning that Applicative, because it looks like type curring makes inheritance impossible here.
  • Are there other non-obvious "connections" (like Arrow->Applicative) I'm missing?
  • Which "useful" type classes are missing in this hierarchy?

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

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

发布评论

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

评论(1

雪花飘飘的天空 2024-11-16 19:43:40
  1. 您应该确保查阅typeclassopedia

  2. Edward Kmett 一直在做自耕农的工作,试图构建一个丰富的、理智的、核心类的层次结构,从半群开始并向前推进。值得直接与他联系,但请查看 semigroupoids 和许多他上传的相关包以获得一些指导:

  1. You should make sure to consult the typeclassopedia.

  2. Edward Kmett has been doing yeoman's work in trying to construct a rich, sane, hierarchy of core classes, starting with semigroups and moving forward. It's worth corresponding with him directly, but take a look at semigroupoids and the many related packages he's uploaded for some pointers:

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