Is the following a definition of structural induction?
foldr f a (xs::ys) = foldr f (foldr f a ys) xs
Can someone give me an example of structural induction in Haskell?
Is the following a definition of structural induction?
foldr f a (xs::ys) = foldr f (foldr f a ys) xs
Can someone give me an example of structural induction in Haskell?
You did not specify it, but I will assume
::
means list concatention and use++
, since that is the operator used in Haskell. To prove this, we will perform induction onxs
. First, we show that the statement holds for the base case (i.e.xs = []
)and
Now, we assume that the induction hypothesis
foldr f a (xs ++ ys) = foldr f (foldr f a ys) xs
holds forxs
and show that it will hold for the listx:xs
as well.and
Now, by our induction hypothesis, we know that
k1
andk2
are equal, thereforeThus proving our hypothesis.