Purescript中是否可以进行默认编程?

时间:2015-05-01 18:34:54

标签: functional-programming purescript

隐性编程也称为无点样式,例如http://en.wikipedia.org/wiki/Tacit_programming Purescript中的一个选项?

1 个答案:

答案 0 :(得分:4)

看看PureScript Prelude source,我会这样说:

instance functorFn :: Functor ((->) r) where
  map = compose  -- point-free!

http://try.purescript.org/?session=3538ae1c-eece-8f50-ad0c-e1504846a793中的示例:

foldr f z Nil = z
foldr f z (x:xs) = f x (subfold xs)
  where subfold = foldr f z

sum = foldr (+) 0

main = trace $ show $ sum (1:2:3:4:Nil)  -- prints: 10

(需要自己定义foldr,因为我无法导入任何模块)