[Haskell-beginners] \x -> x < 0.5 && x > -0.5
Isaac Dupree
ml at isaac.cedarswampstudios.org
Mon Oct 19 23:06:43 EDT 2009
Michael Mossey wrote:
> Eliminating variables and working with function combinations has
> benefits. The one suggestion I've seen here that seems to be right on
> the money is
>
> liftM2 (&&) (< 0.5) (> -0.5)
yep, I might not write it myself, but it's definitely the only one
straightforward enough to perhaps justify itself.
now for a completely different suggestion; you write
> filter (\x -> x < 0.5 && x > -0.5) xs
but as a reader I would find it clearer to switch the order to numerical:
filter (\x -> x > -0.5 && x < 0.5) xs
(in this particular instance, we can observe numerical properties and
even change to (\x -> abs x < 0.5) if we so desire. Which can be
written point-free as ((< 0.5) . abs), if you want to.)
-Isaac
More information about the Beginners
mailing list