[Haskell-beginners] Re: \x -> x < 0.5 && x > -0.5

Brent Yorgey byorgey at seas.upenn.edu
Mon Oct 19 13:21:07 EDT 2009


On Mon, Oct 19, 2009 at 12:07:19PM +0200, Christian Maeder wrote:
> Michael Mossey schrieb:
> > Is there a nifty way to write
> > 
> > filter (\x -> x < 0.5 && x > -0.5) xs
> > 
> > without explicitly using x?
> 
> Hoogle did not find a function of type:
> 
> (b -> b -> b) -> (a -> b) -> (a -> b) -> a -> b
> 
> or (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d

Apparently Hoogle does not know to try unifying m b with a -> b.  As
others have pointed out, a function of this type (actually, a more
general type) does exist, namely, liftM2.

-Brent


More information about the Beginners mailing list