再帰関数をポイントフリー定義に変換できるかどうか知りたいです。
簡単な再帰関数を取ると。
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
無意味にしたいからです。
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)