我想知道是否可以将递归函数转换为无点定义。
如果我们采用一个简单的递归函数。
factorial :: int-> int
factorial 0=1
factorial n+1= (n+1) *factorial n
如果我们有非递归定义。
factorial :: int-> int
factorial n= product [1..n]
<=> factorial n = product.enumFromTo 1 n
<=> factorial = product.enumFromTo 1
但是我怎样才能对递归定义做同样的事情呢?
我问的原因是我想让transformationsApply
pointfree。
transformationsApply :: Eq a => a -> ([a] -> [a]) -> [([a], [a])] -> [a] -> Maybe [a]
transformationsApply _ _ [] _= Nothing
transformationsApply wc func ((a,b):xs) (y:ys)
= orElse (transformationApply wc func (y:ys) (a,b))
(transformationsApply wc func xs (y:ys))
transformationApply
上面使用的定义为
transformationApply :: Eq a => a -> (([a] -> [a]) -> ([a] -> (([a], [a]) -> Maybe [a])))
transformationApply wc func xs (a,b)
= mmap ((substitute wc b).func) (match wc a xs)