[Haskell-beginners] Re: \x -> x < 0.5 && x > -0.5
Heinrich Apfelmus
apfelmus at quantentunnel.de
Mon Oct 19 06:02:19 EDT 2009
Michael Mossey wrote:
> Is there a nifty way to write
>
> filter (\x -> x < 0.5 && x > -0.5) xs
>
> without explicitly using x?
>
> Maybe arrows? I have a vague understanding that arrows can "send" an
> argument to more than one computation.
That's a job for the reader monad.
Lambda Fu, form 53 - silent reader of truth
import Control.Monad
import Control.Monad.Reader
filter (liftM2 (&&) (< 0.5) (> -0.5)) xs
Regards,
apfelmus
--
http://apfelmus.nfshost.com
More information about the Beginners
mailing list