Categorical structure in Haskell

て烟熏妆下的殇ゞ 提交于 2019-12-05 02:21:33

Constraints in Haskell also form a category. The objects are the constraints, and the arrows mean "this constraint implies this other constraint". So every constraint implies itself, and there's an arrow between Monad f and Applicative f, between Ord a and Eq a and between Ord a and Ord [a].

It is a thin category, so there is at most one arrow between two objects.

Gabriel Gonzalez has blogged about this. Here's one such post: http://www.haskellforall.com/2012/08/the-category-design-pattern.html

In it, he calls Hask "the function category", and also discusses "the Kleisli category" and "the pipes category." These are all examples of instances of the Category typeclass in Haskell. The Category typeclass in Haskell is a subset of the categories you can find in Haskell.

I once uploaded an educational package that demonstrates one example of this. I called it MHask.

http://hackage.haskell.org/package/MHask

Copied from the hackage page:

MHask is the category where

  • The objects are Haskell types of kind (* → *) that have an instance of Prelude.Monad
  • An arrow from object m to object n is a Haskell function of the form (forall x. m x → n x)
  • Arrow composition is merely a specialization of Haskell function composition
  • The identity arrow for the object m is the Prelude.id function in Haskell, specialized to (forall x. m x → m x)

Caveat emptor; I have not looked at this in a long time. There may be mistakes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!