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

Paul Visschers mail at paulvisschers.net
Mon Oct 19 06:11:30 EDT 2009


Wouldn't it be better to make an instance of the Boolean class for
functions, that way you could just write:
filter ((< 0.5) && (> -0.5)) xs
Not sure about the syntax, as the Haskell site is down. Also it will
require that you install and import the Boolean class.

One could ask if any of these methods are more readable than the
original though.

Paul

Heinrich Apfelmus wrote:
> 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
> 
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners


More information about the Beginners mailing list