More efficient tail of church encoded list
问题 This is a literate haskell post. Simply save it as "ChurchList.lhs" to run it. > {-# LANGUAGE Rank2Types #-} A Church encoded list is a way of representing a list via a function. It resembles both folding and continuation passing style. > newtype ChurchList a = CList {runCList :: forall r. (a -> r -> r) -> r -> r} For illustration as to how this corresponds to a list, here is a O(n) isomorphism > fromList :: [a] -> ChurchList a > fromList xs = CList $ \cons empty -> foldr cons empty xs >