范畴论中若干概念的实现
pycategories的Python项目详细描述
pycategories是一个python 3库,它实现了category theory中的思想,如monoids、functor和monad。它提供了一个受haskell影响的接口,用于定义那些类型类的实例,并直接定义了几个实例,例如maybe monad:
>>> from categories import apply >>> from categories.maybe import Just, Nothing >>> f = Just(lambda x: x ** 2) >>> x = Just(17) >>> apply(f, x) Just(289) >>> apply(f, Nothing()) Nothing
或者定义自己的类型类实例:
>>> from categories import mappend, mempty, monoid >>> monoid.instance(dict, lambda: {}, lambda a, b: dict(**a, **b)) >>> mappend({'foo': 'bar'}, {'rhu': 'barb'}) {'foo': 'bar', 'rhu': 'barb'}
安装
pip install pycategories
要克隆repo并安装用于开发的依赖项:
git clone https://gitlab.com/danielhones/pycategories cd pycategories pip install -e .[dev]
许可证
pycategories是根据MIT License