module Inductive where -- Lists of integers. data MyListZ = Nil | Node Integer MyListZ deriving Show example_MyListZ = Node 4 (Node 1 (Node 6 Nil)) -- Structural recursion. It's foldr but different argument order. srec_MyListZ :: forall r. MyListZ -> r -> (Integer -> r -> r) -> r srec_MyListZ xs ifNil ifNode = go xs where go Nil = ifNil go (Node x xt) = ifNode x (go xt) mySum :: MyListZ -> Integer mySum xs = srec_MyListZ xs 0 (+)