Skip to content

Commit

Permalink
Add a sample, from the web page
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell committed Jun 1, 2007
1 parent cbeb0e4 commit 46da6fa
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions sample.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
We have developed a method for short-cut fusion using |foldr|/|build|. By introducing the definition:

\begin{code}
build :: ((a -> [a] -> [a]) -> [b] -> c) -> c
build g = g (:) []
\end{code}

The standard definition of |map| is:

\begin{code}
map :: (a -> b) -> [a] -> [b]
map f [] = []
map f (x:xs) = f x : map f xs
\end{code}

But we redefine it as:

\begin{code}
map :: (a -> b) -> [a] -> [b]
map f = foldr ((:) . f) []
\end{code}

Which now allows us to have the property:

\begin{code}
propEq g k z = foldr k z (build g) == g k z
\end{code}

0 comments on commit 46da6fa

Please sign in to comment.