[Haskell-cafe] Short-circuiting a fold
dmhouse at gmail.com
Thu Apr 5 14:19:17 EDT 2007
On 05/04/07, Kurt Hutchinson <kelanslists at gmail.com> wrote:
> > ssfold p f z = head . dropWhile ( not . p ) . scanl f z
I'd prefer find instead of head . dropWhile (not . p), making the
result type a Maybe, as this is essentially equivalent to searching
through the result of a scan for a specific value, so it should follow
find's example and use Maybe for its partiality.
> I want to see some real creativity here, so pull out all the stops.
You may also be interested in the Compose experiment : a bit of fun
seeing how many different ways compose :: [a -> a] ->(a -> a) could be
defined. Most are quite silly, but the solution involving the State
monad, for example, is really quite elegant.
-David House, dmhouse at gmail.com
More information about the Haskell-Cafe