On Wed, Jul 07, 2004 at 01:18:54PM +0100, Graham Klyne wrote:
There's a pattern of higher-order function usage I find myself repeatedly wanting to use, exemplified by the following:
[[
-- combineTest :: (Bool->Bool->Bool) -> (a->Bool) -> (a->Bool) -> (a->Bool)
combineTest :: (b->c->d) -> (a->b) -> (a->c) -> a -> d
combineTest c t1 t2 = \a -> c (t1 a) (t2 a)
(.&.) :: (a->Bool) -> (a->Bool) -> (a->Bool)
(.&.) = combineTest (&&)


(.|.) :: (a->Bool) -> (a->Bool) -> (a->Bool)
(.|.) = combineTest (||)

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.


Henk-Jan van Tuyl


-------------------------------------------------------------------- Festina Lente Hasten Slowly Haast U langzaam Eile langsam Skynd dig langsomt Affrettati lentamente SpÄchej pomalu Skynda lÃngsamt Desiderius Erasmus -------------------------------------------------------------------- -- Met vriendelijke groet, Herzliche GrÃÃe, Best regards, Henk-Jan van Tuyl


-------------------------------------------------------------------- Festina Lente Hasten Slowly Haast U langzaam Eile langsam Skynd dig langsomt Affrettati lentamente SpÄchej pomalu Skynda lÃngsamt Desiderius Erasmus -------------------------------------------------------------------- _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell

Reply via email to