Java 中的 Haskell 类型类层次结构
我编写了一个库,其中包含类似于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该确保查阅typeclassopedia。
Edward Kmett 一直在做自耕农的工作,试图构建一个丰富的、理智的、核心类的层次结构,从半群开始并向前推进。值得直接与他联系,但请查看 semigroupoids 和许多他上传的相关包以获得一些指导:
You should make sure to consult the typeclassopedia.
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: