Is it possible to rewrite any recursive definition with foldr?

Let's say that I have a common recursive definition in haskell:

foo a0 a1 ... = base_case
foo b0 b1 ...          
    | cond1 = recursive_case_1
    | cond2 = recursive_case_2
    ...

Can it always correspond with foldr? Can this be proved?

+4
source share
2 answers

If we interpret your question literally, we can write const value foldrto achieve any value, as @DanielWagner noted in the comment.

, Haskell "" /, , foldr . , , .

, () . , .

f x = f x
-- or even
a = a

, , .

, .

fix :: (a -> a) -> a
fix f = f (fix f)

: , Haskell? , ?

, , ( ), .

. , "i - ". eval i x i - x ( , ). , , , . , eval Haskell, Haskell Haskell ( : -P), .

f n = succ $ eval n n

( ), Haskell, . , , , i -th program.

eval i x = f x

x.

eval i i = f i = succ $ eval i i

- . .

+3

, , , ( fold s, foldr).

. (pdf)

+3

All Articles