Re[Haskell-cafe] cursive to foldr

David Menendez dave at zednenem.com
Wed Nov 18 00:01:38 EST 2009


On Tue, Nov 17, 2009 at 10:01 PM, Luke Palmer <lrpalmer at gmail.com> wrote:
> filter even [0..]    -->    [0,2,4,6,8,...]
> searchList even [0...]   -->   Just [0,2,4,6,8,...]
>
> searchList gives Nothing in exactly those cases that filter gives [].
> They give _|_ in exactly the same situations.  searchList could well
> be defined as:
>
> searchList p xs = if null ys then Nothing else Just ys
>    where ys = filter p xs
>
> null is strict, so searchList is just as strict as filter.

You're right. I was thinking of traverse with an exception monad.

To make up for it, I'll note that with the recently (re)proposed
mfilter, you can define searchList as:

searchList p = mfilter (not . null) . Just . filter p

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Haskell-Cafe mailing list