一个试图为蟒蛇3复制哈斯克尔序曲的图书馆
pylude的Python项目详细描述
克隆Python3的哈斯克尔序曲: http://hackage.haskell.org/package/base-4.8.1.0/docs/Prelude.html
*让python再次变得伟大!*
功能
newtype函数
Just,Nothing=newType('Maybe',('Just',1),('Nothing',0),deriving={Eq,Show})
构造函数匹配
defisJust(x):returnJust(match=x)defisNothing(x):returnx==Nothing
类型类
defmapB(func,b):returnbT,F=newType("B",("T",0),("F",0),deriving={Eq,Show},implements={Functor:{"fmap":mapB}})print(fmap(lambdax:x*2,T))# 'T()'
操作员
# Application operator $ as |@pyludeff(x):returnxprint(f|(lambdax:x*3)|(lambdax:x+1)|2)#9# Function composition . as *g=(lambdax:x*3)*f*(lambdax:x+1)*(lambdax:x+1)print(g(2))#8