Ternary operators in Haskell, an observation (was: [Haskell] Do the libraries define S' ?)

John Meacham john at repetae.net
Mon Aug 2 17:05:01 EDT 2004

On Mon, Aug 02, 2004 at 10:54:33PM +0200, hjgtuyl at chello.nl wrote:
> The operators can be also defined as follows:
>    (.&.) f g x = (f x) && (g x)
>    (.|.) f g x = (f x) || (g x)
> It is clear from these definitions, that the operators are ternary
> operators.
> As operators are essentially the same as functions, in Haskell, any number
> of parameters can be given in an operator definition.

You might be interested in my BooleanAlgebra class, which replaces the
various boolean operators from the prelude with overloaded versions
with various useful instances. 

The really nice thing is the instance for Bool is exactly the same as
the prelude version so this can be dropped into existing code without
change (modulo the monomorphism restriction).

In particular, there is an instance for the boolean algebra of
predicates, so you can say f && g directly where f and g are functions
which return bool.


it also gives you perl-like short circuting, so 
Just 'a' || Just 'b' -> Just 'a' 
and so forth...


John Meacham - ⑆repetae.net⑆john⑈ 

More information about the Haskell mailing list